Check existence of a key
This pattern is licensed under the CC0 Public Domain Dedication.
Requires c++11 or newer.
Check if a particular key is in an associative container.
On line 6, we create a
std::map as an example
associative container and initialize it with key-value pairs.
On line 8, we count the number of occurrences of the key
by using the member function
"b" is in
count will return 1; otherwise it will return
Note: in C++14, an instance of the searched key will not be created if the container’s comparator is transparent and supports the appropriate comparison without conversions.
09 December 2017