[flat.map.overview] (original) (raw)

23 Containers library [containers]

23.6 Container adaptors [container.adaptors]

23.6.8 Class template flat_map [flat.map]

23.6.8.1 Overview [flat.map.overview]

A flat_map is a container adaptor that provides an associative container interface that supports unique keys (i.e., contains at most one of each key value) and provides for fast retrieval of values of another type Tbased on the keys.

flat_map meets the requirements of an associative container ([associative.reqmts]), except that:

[Note 1:

A flat_map does not meet the additional requirements of an allocator-aware container ([container.alloc.reqmts]).

— _end note_]

A flat_map also provides most operations described in [associative.reqmts] for unique keys.

This means that a flat_map supports the a_uniq operations in [associative.reqmts]but not the a_eq operations.

For a flat_map<Key, T>the key_type is Key and the value_type is pair<Key, T>.

Descriptions are provided here only for operations on flat_map that are not described in one of those sets of requirements or for operations where there is additional semantic information.

A flat_map maintains the following invariants:

If any member function in [flat.map.defn] exits via an exception the invariants are restored.

[Note 2:

This can result in the flat_map being emptied.

— _end note_]

Any type Cthat meets the sequence container requirements ([sequence.reqmts]) can be used to instantiate flat_map, as long asC​::​iterator meets the Cpp17RandomAccessIterator requirements and invocations of member functions C​::​size and C​::​max_size do not exit via an exception.

In particular, vector ([vector]) and deque ([deque]) can be used.

[Note 3:

vector<bool> is not a sequence container.

— _end note_]

The program is ill-formed ifKey is not the same type as KeyContainer​::​value_type orT is not the same type as MappedContainer​::​value_type.

The effect of calling a constructor that takes both key_container_type and mapped_container_type arguments with containers of different sizes is undefined.

The effect of calling a constructor or member function that takes a sorted_unique_t argument with a container, containers, or range that is not sorted with respect to key_comp(), or that contains equal elements, is undefined.