function template
<unordered_set>
std::swap (unordered_set)template <class Key, class Hash, class Pred, class Alloc> void swap ( unordered_set<Key,Hash,Pred,Alloc>& lhs, unordered_set<Key,Hash,Pred,Alloc>& rhs );
Exchanges contents of two unordered_set containers
The contents of container lhs are exchanged with those of rhs. Both container objects must be of the same type (same template parameters), although sizes may differ.After the call to this member function, the elements in lhs are those which were in rhs before the call, and the elements of rhs are those which were in lhs. Other objects kept internally by the containers (such as their hasher or key_equal objects) are also swapped.
This is a specialization of the generic algorithm swap that improves its performance by exchanging internal pointers to data, without actually performing any copies or moves on the individual elements.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// swap (unordered_set specialization)
#include <iostream>
#include <string>
#include <unordered_set>
int main ()
{
std::unordered_set<std::string>
first = {"Metropolis","Solaris","Westworld"},
second = {"Avatar","Inception"};
swap(first,second);
std::cout << "first:";
for (const std::string& x: first) std::cout << " " << x;
std::cout << std::endl;
std::cout << "second:";
for (const std::string& x: second) std::cout << " " << x;
std::cout << std::endl;
return 0;
}
first: Inception Avatar second: Westworld Metropolis Solaris
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4