CodesJava

Easy learning with example program codes

CPP Set

Sets in CPP are used to store sorted key. They are the associative containers. Each key in a set is unique. CPP facilitates insertion and deletion of a key in a set but do not allow any modifications.

Member Functions of a CPP Set:

Allocator:

FUNCTIONUSES
get_allocatorTo return an allocator object to construct the set.

 

 Capacity:

FUNCTIONUSES
empty()To determine whether the set is empty or not.
max_size()To determine the maximum size of the set.
size()To determine number of elements in the set.

 

Constructor/Destructor:

FUNCTIONUSES
(constructor)To construct a set.
(destructor)To destruct a set.
operator=To copy the elements of the set to another set.

 

Iterators:

FUNCTIONUSES
begin()To point to the first element of the set.
cbegin()To return a constant iterator to the beginning of the set.
cend()To return a constant iterator to the end.
crbegin()To return a const reverse iterator to the beginning.
crend()To return a const reverse iterator to the end.
end()To return an iterator to the end.
rbegin()To return a reverse iterator to the beginning.
rend()To return a reverse iterator to the end.

 

Modifiers:

FUNCTIONUSES
clear()To remove all the elements of the set.
erase()To delete the specified element.
emplace()To construct and insert a new element at a specified position.
emplace_hint()To construct and insert a new element at a specified position by hint.
insert()To insert a new element in the set..
swap()To exchange the contents of two sets.

 

Non-Member Overloaded Functions:

FUNCTIONUSES
operator==To determine whether the two sets are equal or not.
operator!=To determine whether the two sets are equal or not.
operator<=To determine whether the first set is less than or equal to other or not.
operator<To determine whether the first set is less than other or not.
operator>=To determine whether the first set is greater than equal to other or not.
operator>To determine whether the first set is greater than other or not.
swap()To exchange the contents of two sets.

 

Observers:

FUNCTIONUSES
key_compTo return a copy of key comparison object.
value_compTo return a copy of value comparison object.

 

Operations:

FUNCTIONUSES
countTo get the number of elements matching with given key.
equal_rangeTo get the range of elements matches with given key.
FindTo find an element with given key.
lower_boundTo get an iterator to lower bound.
upper_boundTo get an iterator to upper bound.

 

Please follow and like us:
error
Posted in CPP   








Copyright © 2019 CodesJava DMCA.com Protection Status