TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ set

C++ set tutorial for beginners and professionals with examples on constructor, destructor, operator=(), begin(), cbegin(), cend(), end(), crbegin(), empty(), max_size(), clear(), emplace_hint(), key_comp(), swap() etc.

<< Back to CPP

C++ STL Set

Introduction to set

Sets are part of the C++ STL (Standard Template Library). Sets are the associative containers that stores sorted key, in which each key is unique and it can be inserted or deleted but cannot be altered.

Syntax

template < class T,                             // set::key_type/value_type
           class Compare = less<T>,        // set::key_compare/value_compare
           class Alloc = allocator<T>         // set::allocator_type
           > class set;

Parameter

T: Type of element stored in the container set.

Compare: A comparison class that takes two arguments of the same type bool and returns a value. This argument is optional and the binary predicate less<T>, is the default value.

Alloc: Type of the allocator object which is used to define the storage allocation model.

Member Functions

Below is the list of all member functions of set:

Constructor/Destructor

Functions Description
(constructor) Construct set
(destructor) Set destructor
operator= Copy elements of the set to another set.

Iterators

Functions Description
Begin Returns an iterator pointing to the first element in the set.
cbegin Returns a const iterator pointing to the first element in the set.
End Returns an iterator pointing to the past-end.
Cend Returns a constant iterator pointing to the past-end.
rbegin Returns a reverse iterator pointing to the end.
Rend Returns a reverse iterator pointing to the beginning.
crbegin Returns a constant reverse iterator pointing to the end.
Crend Returns a constant reverse iterator pointing to the beginning.

Capacity

Functions Description
empty Returns true if set is empty.
Size Returns the number of elements in the set.
max_size Returns the maximum size of the set.

Modifiers

Functions Description
insert Insert element in the set.
Erase Erase elements from the set.
Swap Exchange the content of the set.
Clear Delete all the elements of the set.
emplace Construct and insert the new elements into the set.
emplace_hint Construct and insert new elements into the set by hint.

Observers

Functions Description
key_comp Return a copy of key comparison object.
value_comp Return a copy of value comparison object.

Operations

Functions Description
Find Search for an element with given key.
count Gets the number of elements matching with given key.
lower_bound Returns an iterator to lower bound.
upper_bound Returns an iterator to upper bound.
equal_range Returns the range of elements matches with given key.

Allocator

Functions Description
get_allocator Returns an allocator object that is used to construct the set.

Non-Member Overloaded Functions

Functions Description
operator== Checks whether the two sets are equal or not.
operator!= Checks whether the two sets are equal or not.
operator< Checks whether the first set is less than other or not.
operator<= Checks whether the first set is less than or equal to other or not.
operator> Checks whether the first set is greater than other or not.
operator>= Checks whether the first set is greater than equal to other or not.
swap() Exchanges the element of two sets.

Next TopicSet constructor




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf