
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Set Library - swap Function
Description
It exchanges the content of the container by the content of x.
Declaration
Following are the ways in which std::set::swap works in various C++ versions.
C++98
void swap (set& x);
C++11
void swap (set& x);
Return value
none
Exceptions
It never throws exception.
Time complexity
Time complexity is constant.
Example
The 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
Advertisements