The C++ Standard Library
- C++ Library - <valarray>
- C++ Library - <utility>
- C++ Library - <typeinfo>
- C++ Library - <tuple>
- C++ Library - <thread>
- C++ Library - <string>
- C++ Library - <stdexcept>
- C++ Library - <regex>
- C++ Library - <numeric>
- C++ Library - <new>
- C++ Library - <memory>
- C++ Library - <locale>
- C++ Library - <limits>
- C++ Library - <functional>
- C++ Library - <exception>
- C++ Library - <complex>
- C++ Library - <atomic>
- C++ Library - <streambuf>
- C++ Library - <sstream>
- C++ Library - <ostream>
- C++ Library - <istream>
- C++ Library - <iostream>
- C++ Library - <iosfwd>
- C++ Library - <ios>
- C++ Library - <iomanip>
- C++ Library - <fstream>
- C++ Library - Home
The C++ STL Library
- C++ Library - <iterator>
- C++ Library - <algorithm>
- C++ Library - <vector>
- C++ Library - <unordered_set>
- C++ Library - <unordered_map>
- C++ Library - <stack>
- C++ Library - <set>
- C++ Library - <queue>
- C++ Library - <map>
- C++ Library - <list>
- C++ Library - <forward_list>
- C++ Library - <deque>
- C++ Library - <bitset>
- C++ Library - <array>
C++ Programming Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
C++ Library - <set>
Introduction
A set is an Associative container which contains a sorted set of unique objects of type Key. Each element may occur only once, so duppcates are not allowed.
There are four kind of Associative containers: set, multiset, map and multimap.
The value of the elements in a set cannot be modified once in the container, i.e., the elements are always const. But they can be inserted or removed from the container.
set containers are generally slower than unordered_set containers in accessing inspanidual elements by their key, but they allow the direct iteration on subsets based on their order.
Definition
Below is definition of std::set from <set> header file
template < class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> > class set;
Parameters
Key − Type of the element contained.
Key may be substituted by any other data type including user-defined type.
Member types
Following member types can be used as parameters or return type by member functions.
Sr.No. | Member types | Definition |
---|---|---|
1 | key_type | Key |
2 | value_type | Key |
3 | reference | Allocator::reference value_type& |
4 | const_reference | Allocator::const_reference const value_type& |
5 | pointer | Allocator::pointer std::allocator_traits<Allocator>::pointer |
6 | const_pointer | Allocator::const_pointer std::allocator_traits<Allocator>::const_pointer |
7 | iterator | BidirectionalIterator |
8 | const_iterator | constant BidirectionalIterator |
9 | reverse_iterator | std::reverse_iterator <iterator> |
10 | const_reverse_iterator | std::reverse_iterator <const_iterator> |
11 | size_type | Unsigned Integer Type (std::size_t) |
12 | difference_type | Signed Integer Type (std::ptrdiff_t) |
13 | key_compare | Compare |
14 | value_compare | Compare |
15 | allocator_type | Allocator |
Functions from <set>
Below is pst of all methods from <set> header.
MEMBER FUNCTIONS
DEFAULT MEMBER FUNCTIONS
Sr.No. | Method & Description |
---|---|
1 | Constructs the set container. |
2 | Constructs the set container with contents of the range. |
3 | Constructs the set container with the copy of other set. |
4 | Constructs the set container with the contents of other set using move semantics. |
5 | Constructs the set container with contents of the iniapzer pst. |
6 | Destructs the set container. |
7 | Assigns values to the set container. |
ITERATORS
Sr.No. | Method & Description |
---|---|
1 | Returns the iterator to beginning. |
2 | Returns the const iterator to beginning. |
3 | Returns the iterator to end. |
4 | Returns the const iterator to end. |
5 | Returns the reverse iterator to reverse beginning. |
6 | Return const reverse iterator to reverse beginning. |
7 | Returns the reverse iterator to reverse end. |
8 | Returns the const reverse iterator to reverse end. |
CAPACITY
Sr.No. | Method & Description |
---|---|
1 | Returns wheteher the set container is empty. |
2 | Returns the number of elements in the set container. |
3 | Returns the maximum number of elements that the set container can hold. |
MODIFIERS
Sr.No. | Method & Description |
---|---|
1 | Removes all elements from the set container. |
2 | Inserts new element in the set container. |
3 | Inserts new element in the set, if its unique. |
4 | Inserts new element in the set, if its unique, with a hint on the inserting position. |
5 | Removes either a single element or a range of elements from the set container. |
6 | Exchanges the content of the container by the content of another set container of the same type. |
LOOKUP
Sr.No. | Method & Description |
---|---|
1 | Returns the number of elements with matching value in the set container. |
2 | Searches the set container for value and returns an iterator to it if found, else returns an iterator to set::end. |
3 | Returns an iterator pointing to the first element in the set container which is not considered to go before value. |
4 | Returns an iterator pointing to the first element in the set container which is considered to go after value. |
5 | Returns the bounds of a range that includes all the elements in the set container that are equivalent to value. |
OBSERVERS
Sr.No. | Method & Description |
---|---|
1 | Returns a copy of the comparison object used by the set container. |
2 | Returns a copy of the comparison object used by the set container. |
ALLOCATOR
Sr.No. | Method & Description |
---|---|
1 | Returns a copy of the allocator object associated with the set container. |