Home | Projects | Notes > C++ Programming > Associative Container - std::set, std::multiset, std::unordered_set, std::unordered_multiset

Associative Container - std::set, std::multiset, std::unordered_set, std::unordered_multiset

 

The STL Sets

Associative Containers

4 Types of Sets

 

std::set

Initialization and Assignment

Common Methods

Sets have no concept of front and back. Also, they don't allow direct access to the elements using [] or at().

For more information, see cppreference.com.

L6: std::set uses an overloaded operator< for ordering, and returns a std::pair<iterator, bool>:

  • first is an interator to the inserted element or to the duplicate element already in the set.

  • second is a boolean indicating success or failure.

L5: Notice that the std::set's find() method is different from the std::find() method in the STL <algorithm> library. You should use std::set's find() because it knows all about the internal implementation of the std::set, and it's going to be much more efficient.

 

std::multiset

 

std::unordered_set

 

std::unordered_multiset

 

Project: Usage of std::set

Ensure that your custom classes provide the following three elements to work correctly with the STL: