Description

Key must be Erasable from the container
(i.e. allocator_traits can destroy it).

Mapped

Mapped must be Erasable from the container
(i.e. allocator_traits can destroy it).

Hash

A unary function object type that acts a hash function for a Key. It takes a single argument of type Key and returns a value of type std::size_t.

Pred

A binary function object that implements an equivalence relation on values of type Key.
A binary function object that induces an equivalence relation on values of type Key.
It takes two arguments of type Key and returns a value of type bool.

Alloc

An allocator whose value type is the same as the container's value type.

The elements are organized into buckets. Keys with the same hash code are stored in the same bucket and elements with equivalent keys are stored next to each other.

The number of buckets can be automatically increased by a call to insert, or as the result of calling rehash.

unordered_multimap
public
types

typedeftypenameallocator_type::pointerpointer;

value_type* if
allocator_type::pointer is not defined.

typedeftypenameallocator_type::const_pointerconst_pointer;

boost::pointer_to_other<pointer, value_type>::type
if allocator_type::const_pointer is not defined.

typedefimplementation-definedsize_type;

An unsigned integral type.

size_type can represent any non-negative value of difference_type.

typedefimplementation-defineddifference_type;

A signed integral type.

Is identical to the difference type of iterator and const_iterator.

typedefimplementation-definediterator;

An iterator whose value type is value_type.

The iterator category is at least a forward iterator.

Convertible to const_iterator.

typedefimplementation-definedconst_iterator;

A constant iterator whose value type is value_type.

The iterator category is at least a forward iterator.

typedefimplementation-definedlocal_iterator;

An iterator with the same value type, difference type and pointer and reference type as iterator.

A local_iterator object can be used to iterate through a single bucket.

typedefimplementation-definedconst_local_iterator;

A constant iterator with the same value type, difference type and pointer and reference type as const_iterator.

A const_local_iterator object can be used to iterate through a single bucket.

typedefimplementation-definednode_type;

See node_handle_map for details.

unordered_multimap
public
construct/copy/destruct

unordered_multimap();

Constructs an empty container using hasher() as the hash function, key_equal() as the key equality predicate, allocator_type() as the allocator and a maximum load factor of 1.0.

Constructs an empty container with at least n buckets,
using hf as the hash function,
eq as the key equality predicate,
a as the allocator and a maximum load factor of 1.0
and inserts the elements from [f, l) into it.

Requires:

If the defaults are used, hasher, key_equal and
allocator_type need to be DefaultConstructible.

If Allocator::select_on_container_copy_construction
exists and has the right signature, the allocator will be
constructed from its result.

Requires:

value_type is copy constructible

unordered_multimap(unordered_multimap&&);

The move constructor.

Notes:

This is implemented using Boost.Move.

Requires:

value_type is move constructible.

On compilers without rvalue reference support the
emulation does not support moving without calling
boost::move if value_type is
not copyable. So, for example, you can't return the
container from a function.

Constructs an empty container with at least n buckets,
using hf as the hash function,
eq as the key equality predicate,
a as the allocator and a maximum load factor of 1.0
and inserts the elements from il into it.

Requires:

If the defaults are used, hasher, key_equal and
allocator_type need to be DefaultConstructible.

unordered_multimap(size_type n,allocator_typeconst& a);

Constructs an empty container with at least n buckets,
using hf as the hash function,
the default hash function and key equality predicate,
a as the allocator and a maximum load factor of 1.0.

Constructs an empty container with at least n buckets,
using a as the allocator, with the
default hash function and key equality predicate
and a maximum load factor of 1.0
and inserts the elements from [f, l) into it.

Constructs an empty container with at least n buckets,
using hf as the hash function,
a as the allocator, with the
default key equality predicate
and a maximum load factor of 1.0
and inserts the elements from [f, l) into it.

Requires:

key_equal needs to be DefaultConstructible.

~unordered_multimap();

Notes:

The destructor is applied to every element, and all memory is deallocated

unordered_multimap&operator=(unordered_multimapconst&);

The assignment operator. Copies the contained elements, hash function, predicate and maximum load factor but not the allocator.

If Alloc::propagate_on_container_copy_assignment
exists and Alloc::propagate_on_container_copy_assignment::value
is true, the allocator is overwritten, if not the
copied elements are created using the existing
allocator.

Requires:

value_type is copy constructible

unordered_multimap&operator=(unordered_multimap&&);

The move assignment operator.

If Alloc::propagate_on_container_move_assignment
exists and Alloc::propagate_on_container_move_assignment::value
is true, the allocator is overwritten, if not the
moved elements are created using the existing
allocator.

Notes:

On compilers without rvalue references, this is emulated using
Boost.Move. Note that on some compilers the copy assignment
operator may be used in some circumstances.

Requires:

value_type is move constructible.

unordered_multimap&operator=(initializer_list<value_type>);

Assign from values in initializer list. All existing elements are either overwritten by the new elements or destroyed.

When inserting a single element, if an exception is thrown by an operation other than a call to hasher the function has no effect.

Notes:

Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.

Pointers and references to elements are never invalidated.

voidinsert(initializer_list<value_type> il);

Inserts a range of elements into the container.

Requires:

value_type is EmplaceConstructible into
X from *first.

Throws:

When inserting a single element, if an exception is thrown by an operation other than a call to hasher the function has no effect.

Notes:

Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.

Pointers and references to elements are never invalidated.

voidinsert(initializer_list<value_type> il);

Inserts a range of elements into the container. Elements are inserted if and only if there is no element in the container with an equivalent key.

Requires:

value_type is EmplaceConstructible into
X from *first.

Throws:

When inserting a single element, if an exception is thrown by an operation other than a call to hasher the function has no effect.

Notes:

Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.

Pointers and references to elements are never invalidated.

node_typeextract(const_iterator position);

Removes the element pointed to by position.

Returns:

A node_type owning the element.

Notes:

In C++17 a node extracted using this method can be inserted into a compatible unordered_map,
but that is not supported yet.

node_typeextract(key_typeconst& k);

Removes an element with key equivalent to k.

Returns:

A node_type owning the element if found, otherwise an empty node_type.

Throws:

Only throws an exception if it is thrown by hasher or key_equal.

Notes:

In C++17 a node extracted using this method can be inserted into a compatible unordered_map,
but that is not supported yet.

iteratorinsert(node_type&& nh);

If nh is empty, has no affect.

Otherwise inserts the element owned by nh

Requires:

nh is empty or nh.get_allocator() is equal to the container's allocator.

Returns:

If nh was empty, returns end().

Otherwise returns an iterator pointing to the newly inserted element.

Throws:

If an exception is thrown by an operation other than a call to hasher the function has no effect.

Notes:

Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.

Pointers and references to elements are never invalidated.

In C++17 this can be used to insert a node extracted from a compatible unordered_map,
but that is not supported yet.

iteratorinsert(const_iterator hint,node_type&& nh);

If nh is empty, has no affect.

Otherwise inserts the element owned by nh

hint is a suggestion to where the element should be inserted.

Requires:

nh is empty or nh.get_allocator() is equal to the container's allocator.

Returns:

If nh was empty, returns end().

Otherwise returns an iterator pointing to the newly inserted element.

Throws:

If an exception is thrown by an operation other than a call to hasher the function has no effect.

Notes:

The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same key.

Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.

Pointers and references to elements are never invalidated.

In C++17 this can be used to insert a node extracted from a compatible unordered_map,
but that is not supported yet.

iteratorerase(const_iterator position);

Erase the element pointed to by position.

Returns:

The iterator following position before the erasure.

Throws:

Only throws an exception if it is thrown by hasher or key_equal.

Notes:

In older versions this could be inefficient because it had to search
through several buckets to find the position of the returned iterator.
The data structure has been changed so that this is no longer the case,
and the alternative erase methods have been deprecated.

size_typeerase(key_typeconst& k);

Erase all elements with key equivalent to k.

Returns:

The number of elements erased.

Throws:

Only throws an exception if it is thrown by hasher or key_equal.

iteratorerase(const_iterator first,const_iterator last);

Erases the elements in the range from first to last.

Returns:

The iterator following the erased elements - i.e. last.

Throws:

Only throws an exception if it is thrown by hasher or key_equal.

In this implementation, this overload doesn't call either function object's methods so it is no throw, but this might not be true in other implementations.

voidquick_erase(const_iterator position);

Erase the element pointed to by position.

Throws:

Only throws an exception if it is thrown by hasher or key_equal.

In this implementation, this overload doesn't call either function object's methods so it is no throw, but this might not be true in other implementations.

Notes:

This method was implemented because returning an iterator to
the next element from erase was expensive, but
the container has been redesigned so that is no longer the
case. So this method is now deprecated.

voiderase_return_void(const_iterator position);

Erase the element pointed to by position.

Throws:

Only throws an exception if it is thrown by hasher or key_equal.

In this implementation, this overload doesn't call either function object's methods so it is no throw, but this might not be true in other implementations.

Notes:

This method was implemented because returning an iterator to
the next element from erase was expensive, but
the container has been redesigned so that is no longer the
case. So this method is now deprecated.

If Allocator::propagate_on_container_swap is declared and
Allocator::propagate_on_container_swap::value is true then the
containers' allocators are swapped. Otherwise, swapping with unequal allocators
results in undefined behavior.

Throws:

Doesn't throw an exception unless it is thrown by the copy constructor or copy assignment operator of key_equal or hasher.

Notes:

The exception specifications aren't quite the same as the C++11 standard, as
the equality predieate and hash function are swapped using their copy constructors.

An iterator pointing to an element with key equivalent to k, or b.end() if no such element exists.

Notes:

The templated overloads are a non-standard extensions which
allows you to use a compatible hash function and equality
predicate for a key of a different type in order to avoid
an expensive type cast. In general, its use is not encouraged.

If Allocator::propagate_on_container_swap is declared and
Allocator::propagate_on_container_swap::value is true then the
containers' allocators are swapped. Otherwise, swapping with unequal allocators
results in undefined behavior.

Effects:

x.swap(y)

Throws:

Doesn't throw an exception unless it is thrown by the copy constructor or copy assignment operator of key_equal or hasher.

Notes:

The exception specifications aren't quite the same as the C++11 standard, as
the equality predieate and hash function are swapped using their copy constructors.