Standard C++ Library Reference
swap

Exchanges the elements of two maps or multimaps.

[map class]
template<class _Kty, class _Ty, class _Pr, class _Alloc>
   void swap(
   map<Key, Traits, Compare, Alloctor >& _Left,
   map<Key, Traits, Compare, Alloctor >& _Right
)
[multimap class]
template<class _Kty, class _Ty, class _Pr, class _Alloc>
void swap(
   multimap<Key, Traits, Compare, Alloctor >& _Left,
   multimap<Key, Traits, Compare, Alloctor >& _Right
)

Parameters

_Right
The map or multimap providing the elements to be swapped, or the map or multimap whose elements are to be exchanged with those of the map or multimap _Left.
_Left
The map or multimap whose elements are to be exchanged with those of the map or multimap _Right.

Remarks

The template function is an algorithm specialized on the container class map to execute the member function _Left.map::swap(_Right) or on the container class multimap to execute the member function _Left.swap (_Right). These are instances of the partial ordering of function templates by the compiler. When template functions are overloaded in such a way that the match of the template with the function call is not unique, then the compiler will select the most specialized version of the template function. The general version of the template function, template <class T> void swap(T&, T&), in the algorithm class works by assignment and is a slow operation. The specialized version in each container is much faster as it can work with the internal representation of the container class.

Example

See the code example for member function map::swap or multimap::swap for an example that uses the template version of swap.

See Also

<map> Members

Page view tracker