Logo

Programming-Idioms

History of Idiom 51 > diff from v26 to v27

Edit summary for version 27 by Catlike:
New Cpp implementation by user [Catlike]

Version 26

2016-10-07, 12:37:40

Version 27

2016-10-28, 08:18:38

Idiom #51 Check if map contains key

Determine whether map m contains an entry for key k

Illustration

Idiom #51 Check if map contains key

Determine whether map m contains an entry for key k

Illustration
Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Imports
#include <map>
Code
bool key_exists = _m.find(_k) == _m.end();
Comments bubble
The map is a std::map. If value is not found, "find" returns end(); else returns the element.
Doc URL
http://www.cplusplus.com/reference/map/map/find/
Demo URL
https://goo.gl/UFCqBw