unordered_multiset::insert
Adds elements.
iterator insert(const value_type& val);
iterator insert(iterator where, const value_type& val);
template<class InIt>
void insert(InIt first, InIt last);
template<class ValTy>
iterator insert(ValTy&& val);
template<class ValTy>
iterator insert(const_iterator where, ValTy&& val);
Parameters
Parameter |
Description |
InIt |
The iterator type. |
ValTy |
The in-place constructor argument type. |
first |
Beginning of range to insert. |
last |
End of range to insert. |
val |
Value to insert. |
where |
Where in container to insert (hint only). |
Remarks
The first member function inserts the element val in the controlled sequence, then returns the iterator that designates the inserted element. The second member function returns insert(val), using where as a starting place within the controlled sequence to search for the insertion point. (Insertion can possibly occur somewhat faster, if the insertion point immediately precedes or follows where.)
The third member function inserts the sequence of element values, for each where in the range [first, last), by calling insert(*where).
The last two member functions behave the same as the first two, except that val is used to construct the inserted value.
If an exception is thrown during the insertion of a single element, the container is left unaltered and the exception is rethrown. If an exception is thrown during the insertion of multiple elements, the container is left in a stable but unspecified state and the exception is rethrown.
Example
// std_tr1__unordered_set__unordered_multiset_insert.cpp
// compile with: /EHsc
#include <unordered_set>
#include <iostream>
#include <string>
typedef std::unordered_multiset<char> Myset;
int main()
{
Myset c1;
c1.insert('a');
c1.insert('b');
c1.insert('c');
// display contents " [c] [b] [a]"
for (Myset::const_iterator it = c1.begin();
it != c1.end(); ++it)
std::cout << " [" << *it << "]";
std::cout << std::endl;
// insert with hint and reinspect
Myset::iterator it2 = c1.insert(c1.begin(), 'd');
for (Myset::const_iterator it = c1.begin();
it != c1.end(); ++it)
std::cout << " [" << *it << "]";
std::cout << std::endl;
// insert range and inspect
Myset c2;
c2.insert(c1.begin(), c1.end());
for (Myset::const_iterator it = c2.begin();
it != c2.end(); ++it)
std::cout << " [" << *it << "]";
std::cout << std::endl;
// insert new and duplicate, and reinspect
c1.insert('e');
c1.insert('a');
for (Myset::const_iterator it = c1.begin();
it != c1.end(); ++it)
std::cout << " [" << *it << "]";
std::cout << std::endl;
// The templatized versions move constructing elements
unordered_multiset< string> c3, c4;
string str1("a"), str2("b");
c3.insert(move(is1));
cout << "After the move insertion, c3 contains: "
<< *c3.begin() << endl;
c4.insert(c4.begin(), move(is2));
cout << "After the move insertion, c4 contains: "
<< *c4.begin() << endl;
return (0);
}
[c] [b] [a] [d] [c] [b] [a] [d] [c] [b] [a] [e] [d] [c] [b] [a] [a] After the move insertion, c3 contains: a After the move insertion, c4 contains: b
Requirements
Header: <unordered_set>
Namespace: std