All Associative Containers
All Associative Containers
A compact index of ordered and unordered associative containers, lookup operations, and container-selection rules.
All Associative Containers
A compact index of ordered and unordered associative containers, lookup operations, and container-selection rules.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
std::mapstd::multimapstd::setstd::multisetThese maintain key order and support ordered queries such as lower_bound, upper_bound, and equal_range.
std::unordered_mapstd::unordered_multimapstd::unordered_setstd::unordered_multisetThese are hash-based and optimize average lookup speed when ordering does not matter.
findcontainscountequal_rangelower_bound, upper_bound for ordered containersinsert, emplace, try_emplace, insert_or_assignerase, extract, mergeextractmergemap when values are attached to keys; use set when the key itself is the value.#include <map>
#include <string>
int main() {
std::map<std::string, int> counts{std::pair{"Ada", 1}, std::pair{"Bjarne", 2}};
auto [it, inserted] = counts.insert({"Grace", 3});
return inserted ? it->second : 1;
}