Logo

Programming-Idioms

History of Idiom 52 > diff from v39 to v40

Edit summary for version 40 by programming-idioms.org:
[C++] Typo in comments

Version 39

2020-05-19, 16:43:04

Version 40

2020-05-21, 16:09:04

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Illustration

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Illustration
Variables
m,v
Variables
m,v
Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Imports
#include <algorithm>
Imports
#include <algorithm>
Code
std::find_if(m.begin(), m.end(), [v](const auto& mo) {return mo.second == v; }) != m.end();
Code
std::find_if(m.begin(), m.end(), [v](const auto& mo) {return mo.second == v; }) != m.end();
Comments bubble
c++ 14

lambda expression is used because in-built functions perform search by key, not by value
Comments bubble
c++ 14

A lambda expression is used because built-in functions would search by key, not by value.
Origin
https://stackoverflow.com/a/50652326
Origin
https://stackoverflow.com/a/50652326