Export (0) Print
Expand All

swap

Exchanges the elements of two hash_sets or hash_multisets.

[hash_set class]
void swap(
   hash_set <Key, Traits, Allocator>& _Left,
   hash_set <Key, Traits, Allocator>& _Right
);
[hash_multiset class]
void swap(
   hash_multiset <Key, Traits, Allocator>& _Left,
   hash_multiset <Key, Traits, Allocator>& _Right
);

Parameters

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

Remarks

The swap template function is an algorithm specialized on the container class hash_set to execute the member function _Left.swap(_Right) and the container class hash_multiset to execute the member function _Left.swap(_Right). This is an instance 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.

In Visual C++ .NET 2003, members of the <hash_map> and <hash_set> header files are no longer in the std namespace, but rather have been moved into the stdext namespace. See The stdext Namespace for more information.

Example

See the code example for member class hash_set::swap or hash_multiset::swap for an example that uses the template version of swap.

See Also

<hash_set> Members

Show:
© 2015 Microsoft