Why std::set is an associative container

A Container is an object used to store other objects and taking care of the management of the memory used by the objects it contains.

An AssociativeContainer is an ordered Container that provides fast lookup of objects based on keys.

std::set is an associative container that contains a sorted set of unique objects of type Key

So what makes it associative? The fact that elements in a set are referenced by their key and not by their absolute position in the container. The key, of course, is the element itself. Think of it as a map where the keys are values are equal and given that, where the duplicate copy of the same content is eliminated.

So what about an unordered set then? std::unordered_set meets the requirements of Container, AllocatorAwareContainer and UnorderedAssociativeContainer

Tags:

C++

Stl