Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template unordered_map

boost::unordered_map — An unordered associative container that associates unique keys with another value.

Synopsis

// In header: <boost/unordered_map.hpp>

template<typename Key, typename Mapped, typename Hash, 
         typename Pred, 
         typename Alloc> 
class unordered_map {
public:
  // types
  typedef                                     ;            
  typedef            ;          
  typedef                                  ;         
  typedef                                    ;              
  typedef                                    ;           
  typedef                                   ;      
  typedef        ;             
  typedef  ;       
  typedef                             ;             // lvalue of value_type.
  typedef                       ;       // const lvalue of value_type.
  typedef                  ;           
  typedef                  ;     
  typedef                  ;            
  typedef                  ;      
  typedef                  ;      
  typedef                  ;
  typedef                  ;           
  typedef                  ;  

  // construct/copy/destruct
  ();
  (,  = ,  = , 
                          = );
  template<typename InputIterator> 
    (, ,  = , 
                   = ,  = , 
                   = );
  ();
  ();
  ();
  (, );
  (, );
  (,  = ,  = , 
                 = ,  = );
  (, );
  (, , );
  template<typename InputIterator> 
    (, , , 
                  );
  template<typename InputIterator> 
    (, , , , 
                  );
  ~();
   ();
   ();
   ();
   () ;

  // size and capacity
   () ;
   () ;
   () ;

  // iterators
   ();
   () ;
   ();
   () ;
   () ;
   () ;

  // modifiers
  template<typename... Args>  (...);
  template<typename... Args>  (, ...);
   ();
   ();
   (, );
   (, );
  template<typename InputIterator>  (, );
   ();
   ();
   ();
   ();
   ();
   (, );
   ();
   ();
   (, );
   ();
   ();
   ();
   ();
  template<typename H2, typename P2> 
     ();
  template<typename H2, typename P2> 
     ();

  // observers
   () ;
   () ;

  // lookup
   ();
   () ;
  template<typename CompatibleKey, typename CompatibleHash, 
           typename CompatiblePredicate> 
     (, , 
                  );
  template<typename CompatibleKey, typename CompatibleHash, 
           typename CompatiblePredicate> 
     
    (, , 
         ) ;
   () ;
   ();
   () ;
   ();
   ();
   () ;

  // bucket interface
   () ;
   () ;
   () ;
   () ;
   ();
   () ;
   ();
   () ;
   () ;
   ();

  // hash policy
   () ;
   () ;
   ();
   ();
   ();
};

// Equality Comparisons
template<typename Key, typename Mapped, typename Hash, typename Pred, 
         typename Alloc> 
   (, 
                  );
template<typename Key, typename Mapped, typename Hash, typename Pred, 
         typename Alloc> 
   (, 
                  );

// swap
template<typename Key, typename Mapped, typename Hash, typename Pred, 
         typename Alloc> 
   (, 
            );

Description

Template Parameters

Key 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.

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

unordered_map public types

  1. typedef ;

    value_type* if allocator_type::pointer is not defined.

  2. typedef ;

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

  3. typedef ;

    An unsigned integral type.

    size_type can represent any non-negative value of difference_type.

  4. typedef ;

    A signed integral type.

    Is identical to the difference type of iterator and const_iterator.

  5. typedef ;

    An iterator whose value type is value_type.

    The iterator category is at least a forward iterator.

    Convertible to const_iterator.

  6. typedef ;

    A constant iterator whose value type is value_type.

    The iterator category is at least a forward iterator.

  7. typedef ;

    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.

  8. typedef ;

    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.

  9. typedef ;

    See node_handle_map for details.

  10. typedef ;

    Structure returned by inserting node_type.

unordered_map public construct/copy/destruct

  1. ();

    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.

    Postconditions:

    size() == 0

    Requires:

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

  2. ( n,  hf = , 
                            eq = ,  a = );

    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.

    Postconditions:

    size() == 0

    Requires:

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

  3. template<typename InputIterator> 
      ( f,  l,  n = , 
                     hf = ,  eq = , 
                     a = );

    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.

  4. ();

    The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.

    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

  5. ();

    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.

  6. ( a);

    Constructs an empty container, using allocator a.

  7. ( x,  a);

    Constructs an container, copying x's contained elements, hash function, predicate, maximum load factor, but using allocator a.

  8. ( x,  a);

    Construct a container moving x's contained elements, and having the hash function, predicate and maximum load factor, but using allocate a.

    Notes:

    This is implemented using Boost.Move.

    Requires:

    value_type is move insertable.

  9. ( il,  n = , 
                   hf = ,  eq = , 
                   a = );

    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.

  10. ( n,  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.

    Postconditions:

    size() == 0

    Requires:

    hasher and key_equal need to be DefaultConstructible.

  11. ( n,  hf,  a);

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

    Postconditions:

    size() == 0

    Requires:

    key_equal needs to be DefaultConstructible.

  12. template<typename InputIterator> 
      ( f,  l,  n, 
                     a);

    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.

    Requires:

    hasher, key_equal need to be DefaultConstructible.

  13. template<typename InputIterator> 
      ( f,  l,  n, 
                     hf,  a);

    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.

  14. ~();

    Notes:

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

 ();

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

 ();

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.

 ();

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

Requires:

value_type is CopyInsertable into the container and CopyAssignable.

 () ;

unordered_map size and capacity

  1.  () ;

    Returns:

    size() == 0
  2.  () ;

    Returns:

    std::distance(begin(), end())
  3.  () ;

    Returns:

    size() of the largest possible container.

unordered_map iterators

  1.  ();
     () ;

    Returns:

    An iterator referring to the first element of the container, or if the container is empty the past-the-end value for the container.
  2.  ();
     () ;

    Returns:

    An iterator which refers to the past-the-end value for the container.
  3.  () ;

    Returns:

    A constant iterator referring to the first element of the container, or if the container is empty the past-the-end value for the container.
  4.  () ;

    Returns:

    A constant iterator which refers to the past-the-end value for the container.

unordered_map modifiers

  1. template<typename... Args>  (... args);

    Inserts an object, constructed with the arguments args, in the container if and only if there is no element in the container with an equivalent key.

    Requires:

    value_type is EmplaceConstructible into X from args.

    Returns:

    The bool component of the return type is true if an insert took place.

    If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.

    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.

    If the compiler doesn't support variadic template arguments or rvalue references, this is emulated for up to 10 arguments, with no support for rvalue references or move semantics.

    Since existing std::pair implementations don't support std::piecewise_construct this emulates it, but using boost::unordered::piecewise_construct.

  2. template<typename... Args> 
       ( hint, ... args);

    Inserts an object, constructed with the arguments args, in the container if and only if there is no element in the container with an equivalent key.

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

    Requires:

    value_type is EmplaceConstructible into X from args.

    Returns:

    If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.

    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.

    If the compiler doesn't support variadic template arguments or rvalue references, this is emulated for up to 10 arguments, with no support for rvalue references or move semantics.

    Since existing std::pair implementations don't support std::piecewise_construct this emulates it, but using boost::unordered::piecewise_construct.

  3.  ( obj);

    Inserts obj in the container if and only if there is no element in the container with an equivalent key.

    Requires:

    value_type is CopyInsertable.

    Returns:

    The bool component of the return type is true if an insert took place.

    If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.

    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.

  4.  ( obj);

    Inserts obj in the container if and only if there is no element in the container with an equivalent key.

    Requires:

    value_type is MoveInsertable.

    Returns:

    The bool component of the return type is true if an insert took place.

    If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.

    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.

  5.  ( hint,  obj);

    Inserts obj in the container if and only if there is no element in the container with an equivalent key.

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

    Requires:

    value_type is CopyInsertable.

    Returns:

    If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.

    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.

  6.  ( hint,  obj);

    Inserts obj in the container if and only if there is no element in the container with an equivalent key.

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

    Requires:

    value_type is MoveInsertable.

    Returns:

    If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.

    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.

  7. template<typename InputIterator> 
       ( first,  last);

    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.

  8.  ( 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.

  9.  ( 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.

  10.  ( 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_multimap, but that is not supported yet.

  11.  ( 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_multimap, but that is not supported yet.

  12.  ( nh);

    If nh is empty, has no affect.

    Otherwise inserts the element owned by nh if and only if there is no element in the container with an equivalent key.

    Requires:

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

    Returns:

    If nh was empty, returns an insert_return_type with: inserted equal to false, position equal to end() and node empty.

    Otherwise if there was already an element with an equivalent key, returns an insert_return_type with: inserted equal to false, position pointing to a matching element and node contains the node from nh.

    Otherwise if the insertion succeeded, returns an insert_return_type with: inserted equal to true, position pointing to the newly inserted element and node empty.

    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_multimap, but that is not supported yet.

  13.  ( hint,  nh);

    If nh is empty, has no affect.

    Otherwise inserts the element owned by nh if and only if there is no element in the container with an equivalent key.

    If there is already an element in the container with an equivalent key has no effect on nh (i.e. nh still contains the node.)

    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().

    If there was already an element in the container with an equivalent key returns an iterator pointing to that.

    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_multimap, but that is not supported yet.

  14.  ( 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.

  15.  ( 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.

  16.  ( first,  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.

  17.  ( 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.

  18.  ( 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.

  19.  ();

    Erases all elements in the container.

    Postconditions:

    size() == 0

    Throws:

    Never throws an exception.

  20.  ();

    Swaps the contents of the container with the parameter.

    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.

  21. template<typename H2, typename P2> 
       ( source);

    Notes:

    Does not support merging with a compatible unordered_multimap yet.

  22. template<typename H2, typename P2> 
       ( source);

    Notes:

    Does not support merging with a compatible unordered_multimap yet.

unordered_map observers

  1.  () ;

    Returns:

    The container's hash function.
  2.  () ;

    Returns:

    The container's key equality predicate.

unordered_map lookup

  1.  ( k);
     ( k) ;
    template<typename CompatibleKey, typename CompatibleHash, 
             typename CompatiblePredicate> 
       ( k,  hash, 
                     eq);
    template<typename CompatibleKey, typename CompatibleHash, 
             typename CompatiblePredicate> 
       
      ( k,  hash, 
            eq) ;

    Returns:

    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.

  2.  ( k) ;

    Returns:

    The number of elements with key equivalent to k.

  3.  ( k);
     ( k) ;

    Returns:

    A range containing all elements with key equivalent to k. If the container doesn't container any such elements, returns std::make_pair(b.end(),b.end()).

  4.  ( k);

    Effects:

    If the container does not already contain an elements with a key equivalent to k, inserts the value std::pair<key_type const, mapped_type>(k, mapped_type())

    Returns:

    A reference to x.second where x is the element already in the container, or the newly inserted element with a key equivalent to k

    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.

  5.  ( k);
     ( k) ;

    Returns:

    A reference to x.second where x is the (unique) element whose key is equivalent to k.

    Throws:

    An exception object of type std::out_of_range if no such element is present.

unordered_map bucket interface

  1.  () ;

    Returns:

    The number of buckets.

  2.  () ;

    Returns:

    An upper bound on the number of buckets.

  3.  ( n) ;

    Requires:

    n < bucket_count()

    Returns:

    The number of elements in bucket n.

  4.  ( k) ;

    Returns:

    The index of the bucket which would contain an element with key k.

    Postconditions:

    The return value is less than bucket_count()

  5.  ( n);
     ( n) ;

    Requires:

    n shall be in the range [0, bucket_count()).

    Returns:

    A local iterator pointing the first element in the bucket with index n.

  6.  ( n);
     ( n) ;

    Requires:

    n shall be in the range [0, bucket_count()).

    Returns:

    A local iterator pointing the 'one past the end' element in the bucket with index n.

  7.  ( n) ;

    Requires:

    n shall be in the range [0, bucket_count()).

    Returns:

    A constant local iterator pointing the first element in the bucket with index n.

  8.  ( n);

    Requires:

    n shall be in the range [0, bucket_count()).

    Returns:

    A constant local iterator pointing the 'one past the end' element in the bucket with index n.

unordered_map hash policy

  1.  () ;

    Returns:

    The average number of elements per bucket.

  2.  () ;

    Returns:

    Returns the current maximum load factor.

  3.  ( z);

    Effects:

    Changes the container's maximum load factor, using z as a hint.

  4.  ( n);

    Changes the number of buckets so that there at least n buckets, and so that the load factor is less than the maximum load factor.

    Invalidates iterators, and changes the order of elements. Pointers and references to elements are not invalidated.

    Throws:

    The function has no effect if an exception is thrown, unless it is thrown by the container's hash function or comparison function.

  5.  ( n);

    Invalidates iterators, and changes the order of elements. Pointers and references to elements are not invalidated.

    Throws:

    The function has no effect if an exception is thrown, unless it is thrown by the container's hash function or comparison function.

unordered_map Equality Comparisons

  1. template<typename Key, typename Mapped, typename Hash, typename Pred, 
             typename Alloc> 
       ( x, 
                       y);

    Return true if x.size() == y.size and for every element in x, there is an element in y with the same for the same key, with an equal value (using operator== to compare the value types).

    Notes:

    The behavior of this function was changed to match the C++11 standard in Boost 1.48.

    Behavior is undefined if the two containers don't have equivalent equality predicates.

  2. template<typename Key, typename Mapped, typename Hash, typename Pred, 
             typename Alloc> 
       ( x, 
                       y);

    Return false if x.size() == y.size and for every element in x, there is an element in y with the same for the same key, with an equal value (using operator== to compare the value types).

    Notes:

    The behavior of this function was changed to match the C++11 standard in Boost 1.48.

    Behavior is undefined if the two containers don't have equivalent equality predicates.

unordered_map swap

  1. template<typename Key, typename Mapped, typename Hash, typename Pred, 
             typename Alloc> 
       ( x, 
                 y);

    Swaps the contents of x and y.

    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.


PrevUpHomeNext