The swap() method of “unordered_set” swaps the contents of two containers. It is public member function. This function:
- Exchanges the content of the container by the content of variable, which is another unordered_set object containing elements of the same type but the sizes may differ.
- After the call to this member function, the elements in this container are those which were in variable before the call, and the elements of variable are those which were in this.
void swap(unordered_set &another_unordered_set);
Parameters: It receives another_unordered_set container object of the same type as this container with which it is to be swapped.
Returns: It does not return any value.
Below program illustrate the unordered_set swap() function :-
before swap :- 1st container : FOR GEEKS 2nd container : GEEKS after swap :- 1st container : GEEKS 2nd container : FOR GEEKS
before swap :- 1st container : 3 2 1 2nd container : 6 5 4 after swap :- 1st container : 6 5 4 2nd container : 3 2 1
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between std::swap and std::vector::swap
- forward_list::swap() in C++ STL
- multimap swap() function in C++ STL
- unordered_set swap() function in C++ STL
- unordered_multimap swap() function in C++ STL
- unordered_multiset swap() function in C++ STL
- unordered_multiset swap() in C++ STL
- swap() in C++
- valarray swap() function in c++
- basic_istream::swap() in C++ with Examples
- atanh() function in C++ STL
- forward_list merge() in C++ STL
- vector rbegin() and rend() function in C++ STL
- unordered_multimap begin() and end() function in C++ STL
- unordered_multiset operator = in C++ STL
- list cbegin() and cend() function in C++ STL
- set vs unordered_set in C++ STL
- unordered_map find in C++ STL
- deque assign() function in C++ STL
- count_if() in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.