set STL container class in C++: Types of constructors, operators

set class is used for the operation on sets having unique keys. A set class is declared as:

template <class Key, class Comp = less<Key>, class Allocator = allocator<Key>> class set

Types of set constructors:

Type-1: Empty set

explicit set(const Comp &cmpfn = Comp( ), const Allocator &a = Allocator( ) );

Type-2: set having same elements as obj.

set(const set<Key, Comp, Allocator> &obj);

Type-3: set having elements in the range i and j.

template <class InIter> set(InIter i, InIter j, const Comp &b = Comp( ), const Allocator &a = Allocator( ));

Types of set operators: ==, <, <=, !=, >, >=

Leave a Reply