
- 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 - operator= Function
Description
It assigns new contents to the container, replacing its current content.
Declaration
Following are the ways in which std::set::operator= works in various C++ versions.
C++98
set& operator= (const set& x);
C++11
set& operator= (const set& x); set& operator= (set&& x); set& operator= (initializer_list<value_type> il)
Return value
It returns *this.
Exceptions
If an exception is thrown, the container is in a valid state.
Time complexity
Linear in size of the container.
Example
The following example shows the usage of std::set::operator=.
#include <iostream> #include <set> int main () { int myints[] = { 10,20,30,40,50 }; std::set<int> first (myints,myints+10); std::set<int> second; second = first; first = std::set<int>(); std::cout << "Size of first: " << int (first.size()) << '\n'; std::cout << "Size of second: " << int (second.size()) << '\n'; return 0; }
The above program will compile and execute properly.
Size of first: 0 Size of second: 8
set.htm
Advertisements