Description

A flat_map is a kind of associative container that supports unique keys (contains at most one of each key value) and provides for fast retrieval of values of another type T based on the keys. The flat_map class supports random-access iterators.

A flat_map satisfies all of the requirements of a container and of a reversible container and of an associative container. A flat_map also provides most operations described for unique keys. For a flat_map<Key,T> the key_type is Key and the value_type is std::pair<Key,T> (unlike std::map<Key, T> which value_type is std::pair<const Key, T>).

Pred is the ordering function for Keys (e.g. std::less<Key>).

A is the allocator to allocate the value_types (e.g. allocator< std::pair<Key, T> >).

flat_map is similar to std::map but it's implemented like an ordered vector. This means that inserting a new element into a flat_map invalidates previous iterators and references

Erasing an element of a flat_map invalidates iterators and references pointing to elements that come after (their keys are bigger) the erased element.

Effects: Constructs an empty flat_map using the specified comparison object and allocator, and inserts elements from the ordered unique range [first ,last). This function is more efficient than the normal range creation for ordered ranges.

Requires: [first ,last) must be ordered according to the predicate and must be unique values.

Effects: Inserts an object of type T constructed with std::forward<Args>(args)... in the container if and only if there is no element in the container with key equivalent to the key of x. p is a hint pointing to where the insert should start to search.

Returns: An iterator pointing to the element with key equivalent to the key of x.

Complexity: Logarithmic search time (constant if x is inserted right before p) plus insertion linear to the elements with bigger keys than x.

Note: If an element it's inserted it might invalidate elements.

iteratoremplace();

iteratoremplace_hint(const_iterator hint);

iteratorerase(const_iterator position);

Effects: Erases the element pointed to by position.

Returns: Returns an iterator pointing to the element immediately following q prior to the element being erased. If no such element exists, returns end().

Complexity: Linear to the elements with keys bigger than position

Note: Invalidates elements with keys not less than the erased element.

size_typeerase(constkey_type& x);

Effects: Erases all elements in the container with key equivalent to x.

Returns: Returns the number of erased elements.

Complexity: Logarithmic search time plus erasure time linear to the elements with bigger keys.

iteratorerase(const_iterator first,const_iterator last);

Effects: Erases all the elements in the range [first, last).

Returns: Returns last.

Complexity: size()*N where N is the distance from first to last.

Complexity: Logarithmic search time plus erasure time linear to the elements with bigger keys.

voidclear();

Effects: erase(a.begin(),a.end()).

Postcondition: size() == 0.

Complexity: linear in size().

voidshrink_to_fit();

Effects: Tries to deallocate the excess of memory created

Throws: If memory allocation throws, or T's copy constructor throws.

Complexity: Linear to size().

iteratorfind(constkey_type& x);

Returns: An iterator pointing to an element with the key equivalent to x, or end() if such an element is not found.

Complexity: Logarithmic.

const_iteratorfind(constkey_type& x)const;

Returns: A const_iterator pointing to an element with the key equivalent to x, or end() if such an element is not found.

Complexity: Logarithmic.s

size_typecount(constkey_type& x)const;

Returns: The number of elements with key equivalent to x.

Complexity: log(size())+count(k)

iteratorlower_bound(constkey_type& x);

Returns: An iterator pointing to the first element with key not less than k, or a.end() if such an element is not found.

Complexity: Logarithmic

const_iteratorlower_bound(constkey_type& x)const;

Returns: A const iterator pointing to the first element with key not less than k, or a.end() if such an element is not found.

Complexity: Logarithmic

iteratorupper_bound(constkey_type& x);

Returns: An iterator pointing to the first element with key not less than x, or end() if such an element is not found.

Complexity: Logarithmic

const_iteratorupper_bound(constkey_type& x)const;

Returns: A const iterator pointing to the first element with key not less than x, or end() if such an element is not found.

Effects: Number of elements for which memory has been allocated. capacity() is always greater than or equal to size().

Throws: Nothing.

Complexity: Constant.

voidreserve(size_type count);

Effects: If n is less than or equal to capacity(), this call has no effect. Otherwise, it is a request for allocation of additional memory. If the request is successful, then capacity() is greater than or equal to n; otherwise, capacity() is unchanged. In either case, size() is unchanged.