It exchanges the content of the container by the content of x.
DeclarationFollowing are the ways in which std::set::swap works in various C++ versions.
C++98void swap (set& x);C++11
void swap (set& x);Return value
none
ExceptionsIt never throws exception.
Time complexityTime complexity is constant.
ExampleThe following example shows the usage of std::set::swap.
#include <iostream> #include <set> main () { int myints[] = {10,20,30,40,50,60}; std::set<int> first (myints,myints+3); std::set<int> second (myints+3,myints+6); first.swap(second); std::cout << "first contains:"; for (std::set<int>::iterator it = first.begin(); it!=first.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; std::cout << "second contains:"; for (std::set<int>::iterator it = second.begin(); it!=second.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0; }
The above program will compile and execute properly.
first contains: 40 50 60 second contains: 10 20 30
set.htm
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