public member function
<unordered_set>

std::unordered_multiset::unordered_multiset

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

(1) empty container constructor (default constructor)
Constructs an empty unordered_multiset 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) range constructor
Constructs an unordered_multiset 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 ums unordered_multiset object.
(4) move constructor (and moving with allocator)
The object acquires the contents of the rvalue ums.
(5) initializer list
Initializes the container with the contents of the list.

Parameters

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).
Member type size_type is an unsigned integral 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.
Member type hasher is defined in unordered_multiset as an alias of its second template parameter (Hash).
eql
Comparison function object, that returns true if the two container object keys passed as arguments are to be considered equal.
Member type key_equal is defined in unordered_multiset as an alias of its third template parameter (Pred).
alloc
Allocator object to be used instead of constructing a new one.
For class instantiations using their version of the default allocator class template, this parameter is not relevant.
Member type allocator_type is defined in unordered_multiset as an alias of its fourth template parameter (Alloc).
first, last
Input iterators to the initial and final positions in a range. The range used is [first,last), which includes all the elements between first and last, including the element pointed by first but not the element pointed by last.
The function template type can be any type of input iterator.
ums
Another unordered_multiset object of the same type (with the same class template arguments), whose contents are either copied or moved.
il
An initializer_list object.
These objects are automatically constructed from initializer list declarators.
Member type value_type is the type of the elements in the container, defined in unordered_multiset as an alias of the first template parameter (Key).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// constructing unordered_multisets
#include <iostream>
#include <string>
#include <unordered_set>

template<class T>
T cmerge (T a, T b) { T t(a); t.insert(b.begin(),b.end()); return t; }

int main ()
{
  std::unordered_multiset<std::string> first;                                // empty
  std::unordered_multiset<std::string> second ( {"red","green","blue"} );    // init list
  std::unordered_multiset<std::string> third ( {"red","yellow","blue"} );    // init list
  std::unordered_multiset<std::string> fourth ( second );                    // copy
  std::unordered_multiset<std::string> fifth ( cmerge(third,fourth) );       // move
  std::unordered_multiset<std::string> sixth ( fifth.begin(), fifth.end() ); // range

  std::cout << "sixth contains:";
  for (const std::string& x: sixth) std::cout << " " << x;
  std::cout << std::endl;

  return 0;
}


Possible output:
sixth contains: yellow red red green blue blue

Complexity

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.

See also

  • 9281021542 2018-02-20
  • 632231541 2018-02-20
  • 9751491540 2018-02-20
  • 8333621539 2018-02-20
  • 995001538 2018-02-20
  • 6477441537 2018-02-20
  • 511981536 2018-02-19
  • 2072881535 2018-02-19
  • 6024461534 2018-02-19
  • 7594061533 2018-02-19
  • 9311341532 2018-02-19
  • 4928331531 2018-02-19
  • 38561530 2018-02-19
  • 7776611529 2018-02-19
  • 3038041528 2018-02-19
  • 9566341527 2018-02-19
  • 3936031526 2018-02-19
  • 9531111525 2018-02-19
  • 291211524 2018-02-19
  • 8962001523 2018-02-19