Logo

Programming-Idioms

History of Idiom 52 > diff from v37 to v38

Edit summary for version 38 by nuraby:
New C++ implementation by user [nuraby]

Version 37

2020-05-10, 21:57:16

Version 38

2020-05-19, 16:40:35

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>
Code
bool result = m.end() != std::find_if(m.begin(), m.end(), [v](const auto& mo) {return mo.second == v; });
Comments bubble
c++ 14

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