public member function
<unordered_map>
std::unordered_multimap::insert (1)iterator insert ( const value_type& val );(2)
template <class P> iterator insert ( P&& val );(3)
iterator insert ( const_iterator hint, const value_type& val );(4)
template <class P> iterator insert ( const_iterator hint, P&& val );(5)
template <class InputIterator> void insert ( InputIterator first, InputIterator last );(6)
void insert ( initializer_list<value_type> il );
Insert elements
Inserts new elements in the unordered_multimap.This effectively increases the container size by the number of elements inserted.
The parameters determine how many elements are inserted and to which values they are initialized:
The signatures taking an argument of type P&&
are only called if P is a type implicitly convertible to value_type.
The signatures taking an argument of type
P&&
are only called if
std::is_constructible<value_type,P&&>
is
true
.
Versions (5) and (6) return no value.
Member type iterator is a forward iterator type.
The storage for the new element is allocated using allocator_traits<allocator_type>::construct(), which may throw exceptions on failure (for the default allocator, bad_alloc is thrown if the allocation request does not succeed).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// unordered_multimap::insert
#include <iostream>
#include <string>
#include <unordered_map>
int main ()
{
std::unordered_multimap<std::string,int>
first,
second = {{"AAPL",200},{"GOOG",100}};
std::pair<std::string,int> mypair ("MSFT",500);
first.insert (mypair); // copy insertion
first.insert (std::make_pair<std::string,int>("GOOG",50)); // move insertion
first.insert (second.begin(), second.end()); // range insertion
first.insert ( {{"ORCL",100},{"GOOG",100}} ); // initializer list insertion
std::cout << "first contains:" << std::endl;
for (auto& x: first)
std::cout << x.first << ": " << x.second << std::endl;
std::cout << std::endl;
return 0;
}
first contains: AAPL: 200 MSFT: 500 ORCL: 100 GOOG: 50 GOOG: 100 GOOG: 100
A rehash is forced if the new container size after the insertion operation would increase above its capacity threshold (calculated as the container's bucket_count multiplied by its max_load_factor).
References to elements in the unordered_multimap container remain valid in all cases, even after a rehash.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4