
- 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 - ~set() Function
Description
The C++ destructor std::set::~set() destructs the set container. This ensures that the used storage is deallocated.
Note: If the elements are pointers, the pointed-to objects are not destroyed. It only ensures all iterators, pointers and references are invalidated.
Declaration
Following are the ways in which std::set::~set() destructor works in various C++ versions.
C++98
~set() destroys all set container elements, and deallocates all the storage capacity allocated by the container using its allocator.
C++11
~set() calls allocator_traits::destroy on each of the contained elements, and deallocates all the storage capacity allocated by the set container using its allocator.
C++14
~set() calls allocator_traits::destroy on each of the contained elements, and deallocates all the storage capacity allocated by the set container using its allocator.
Return value
Destructor never returns any value.
Exceptions
This member function has no effect in case any exception is thrown.
Time complexity
Linear in size of the container, i.e. O(N)
Example
The following example shows the usage of std::set::~set() destructor.
#include <iostream> #include <set> #include <string> using namespace std; int main(void) { //Default constructor std::set<string> t_set; t_set.insert("Tutorials Point"); return 0; }
The above program will compile and execute properly.
The moment it returns from main(); destructor ~set() will be called to destroy the set container 't_set'
set.htm
Advertisements