Skip to content
C++

<map> API Reference

C++ std::map — an ordered associative container of key-value pairs, implemented as a red-black tree.

By EZ4Code Team

std::map

An ordered associative container that contains key-value pairs with unique keys, sorted by key.

std::map::insert(const value_type& val) -> pair<iterator, bool>

Inserts a {key, value} pair. Returns {iterator, bool} where bool is false if the key already existed.

Returns: pair<iterator, bool>

std::map::at(const key_type& k) -> mapped_type&

Returns a reference to the mapped value of k, throwing std::out_of_range if not found.

Returns: mapped_type&

std::map::size() const noexcept -> size_t

Returns the number of elements in the container.

Returns: size_t

std::map::erase(const key_type& k) -> size_type

Removes the element with key k. Returns the number of elements removed (0 or 1).

Returns: size_type

std::map::find(const key_type& k) -> iterator

Returns an iterator to the element with key k, or end() if not found.

Returns: iterator

std::map::empty() const noexcept -> bool

Returns true if the container has no elements.

Returns: bool

More C++ API References