public member function
<unordered_map>

std::unordered_multimap::unordered_multimap

empty (1)
explicit unordered_multimap ( size_type n = /* see below */,                              const hasher& hf = hasher(),                              const key_equal& eql = key_equal(),                              const allocator_type& alloc = allocator_type() );explicit unordered_multimap ( const allocator_type& alloc );
range (2)
template <class InputIterator>         unordered_multimap ( InputIterator first, InputIterator last,                              size_type n = /* see below */,                              const hasher& hf = hasher(),                              const key_equal& eql = key_equal(),                              const allocator_type& alloc = allocator_type() );
copy (3)
unordered_multimap ( const unordered_multimap& umm );unordered_multimap ( const unordered_multimap& umm, const allocator_type& alloc );
move (4)
unordered_multimap ( unordered_multimap&& umm );unordered_multimap ( unordered_multimap&& umm, const allocator_type& alloc );
initializer list (5)
unordered_multimap ( initializer_list<value_type> il, size_type n = /* see below */,                     const hasher& hf = hasher(), const key_equal& eql = key_equal(),                     const allocator_type& alloc = allocator_type() );
empty (1)
unordered_multimap();explicit unordered_multimap ( size_type n,                              const hasher& hf = hasher(),                              const key_equal& eql = key_equal(),                              const allocator_type& alloc = allocator_type() );explicit unordered_multimap ( const allocator_type& alloc );         unordered_multimap ( size_type n, const allocator_type& alloc );         unordered_multimap ( size_type n, const hasher& hf,                              const allocator_type& alloc );
range (2)
template <class InputIterator>  unordered_multimap ( InputIterator first, InputIterator last,                       size_type n = /* see below */,                       const hasher& hf = hasher(),                       const key_equal& eql = key_equal(),                       const allocator_type& alloc = allocator_type() );template <class InputIterator>  unordered_multimap ( InputIterator first, InputIterator last,                       size_type n, const allocator_type& alloc );template <class InputIterator>  unordered_multimap ( InputIterator first, InputIterator last,                       size_type n, const hasher& hf,                       const allocator_type& alloc );
copy (3)
unordered_multimap ( const unordered_multimap& umm );unordered_multimap ( const unordered_multimap& umm, const allocator_type& alloc );
move (4)
unordered_multimap ( unordered_multimap&& umm );unordered_multimap ( unordered_multimap&& umm, const allocator_type& alloc );
initializer list (5)
unordered_multimap ( initializer_list<value_type> il, size_type n = /* see below */,                     const hasher& hf = hasher(), const key_equal& eql = key_equal(),                     const allocator_type& alloc = allocator_type() );unordered_multimap ( initializer_list<value_type> il, size_type n,                     const allocator_type& alloc );unordered_multimap ( initializer_list<value_type> il, size_type n, const hasher& hf,                     const allocator_type& alloc );
Construct unordered_multimap
Constructs an unordered_multimap container object, initializing its contents depending on the constructor version used

(1) empty container constructor (default constructor)
Constructs an empty unordered_multimap object, containing no elements and with a size of zero.
It can construct the container with specific hasher, key_equal and allocator objects, along with a minimum number of hash buckets.
(2) 范围构造函数 ((2) range constructor)
Constructs an unordered_multimap object containing copies of each of the elements in the range[first,last).
(3) copy constructor (and copying with allocator)
The object is initialized to have the same contents and properties as the umm unordered_multimap object.
(4) move constructor (and moving with allocator)
The object acquires the contents of the rvalue umm.
(5) initializer list
Initializes the container with the contents of the list.

参数

n
Minimum number of initial buckets.
This is not the number of elements in the container, but the minimum number of slots desired for the internal hash table on construction.
If this argument is not specified, the constructor determines this automatically (in a way that depends on the particular library implementation).
成员类型size_type是一种无符号整型类型。
hf
Hasher function object. A hasher is a function that returns an integral value based on the container object key passed to it as argument.
成员类型hasheris defined in unordered_multimap as an alias of its third template parameter (Hash).
eql
Comparison function object, that returnstrueif the two container object keys passed as arguments are to be considered equal.
成员类型key_equalis defined in unordered_multimap as an alias of its fourth template parameter (Pred).
alloc
要使用的分配器对象,而不是构造一个新的分配器对象。
对于使用其默认 分配器类模板版本的类实例化,此参数不相关。
成员类型allocator_typeis defined in unordered_multimap as an alias of its fifth template parameter (Alloc).
first, last
指向范围内初始位置和最终位置的输入迭代器。 使用的范围是[first,last),它包括firstlast之间的所有元素,包括first指向的元素,但不包括last指向的元素。
The function template type can be any type of input iterator.
umm
Another unordered_multimap object of the same type (with the same class template arguments), whose contents are either copied or moved.
il
il
这些对象是从初始化列表声明符自动构造的。
成员类型value_typeis the type of the elements in the container, defined in unordered_multimap aspair<const key_type,mapped_type>,其中成员类型key_type是第一个模板参数(键类型)的别名,而mapped_type是第二个模板参数(映射类型,T).

示例

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
26
// constructing unordered_multimaps
#include <iostream>
#include <string>
#include <unordered_map>

typedef std::unordered_multimap<std::string,std::string> stringmap;

stringmap merge (stringmap a,stringmap b) {
  stringmap temp(a); temp.insert(b.begin(),b.end()); return temp;
}

int main ()
{
  stringmap first;                              // empty
  stringmap second ( {{"apple","red"},{"lemon","yellow"}} );       // init list
  stringmap third ( {{"apple","green"},{"strawberry","red"}} );  // init list
  stringmap fourth (second);                    // copy
  stringmap fifth (merge(third,fourth));        // move
  stringmap sixth (fifth.begin(),fifth.end());  // range

  std::cout << "sixth contains:";
  for (auto& x: sixth) std::cout << " " << x.first << ":" << x.second;
  std::cout << std::endl;

  return 0;
}

可能的输出
sixth contains: apple:green apple:red lemon:yellow strawberry:red


复杂度

For the empty (1) and move (4) constructors: constant time.
For the range (2), copy (3), and initializer list (5) constructors: average case linear, worst case quadratic.

另见