Logo

Programming-Idioms

History of Idiom 52 > diff from v38 to v39

Edit summary for version 39 by nuraby:
[C++] result variable was removed

Version 38

2020-05-19, 16:40:35

Version 39

2020-05-19, 16:43: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
bool result = m.end() != std::find_if(m.begin(), m.end(), [v](const auto& mo) {return mo.second == v; });
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

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