Logo

Programming-Idioms

History of Idiom 51 > diff from v31 to v32

Edit summary for version 32 by programming-idioms.org:
[Cpp] Fixed comment

Version 31

2016-11-28, 22:34:09

Version 32

2016-11-28, 22:37:33

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>
Imports
#include <map>
Code
bool key_exists = m.find(_k) != m.end();
Code
bool key_exists = m.find(k) != m.end();
Comments bubble
m is a std::map. If value is not found, "find" returns end(); else returns the element.
Comments bubble
m is a std::map. If value is not found, find returns end(), else it returns an iterator to the element.
Doc URL
http://www.cplusplus.com/reference/map/map/find/
Doc URL
http://www.cplusplus.com/reference/map/map/find/
Demo URL
https://goo.gl/UFCqBw
Demo URL
https://goo.gl/UFCqBw