1

I have a map like this (both of first and second parameters are unique):

std::map<DWORD, DWORD> mapTest;
mapTest.insert(make_pair(1, 101));
mapTest.insert(make_pair(2, 102));
mapTest.insert(make_pair(3, 103));

And I have a searcher, which is work perfectly for the first values of the map:

bool SearchInMap(DWORD firstmap, DWORD * secondmap)
{
    if (mapTest.end() == mapTest.find(firstmap))
        return false;

    *secondmap = mapTest[firstmap];
    return true;
}

But I need another method, which could search in the second parameters and looks like what I showed. If possible I don't want to use for or while cycles. As I know I probably need a find_if search, but I can't handle it.

Thanks in advance you're help!

Gregori
  • 85
  • 7

1 Answers1

1

You can do it in simple way using lambdas.

DWORD val = 103;
auto result = std::find_if(stMap.begin(), stMap.end(), [val](const auto& mo) {return mo.second == val; });

DWORD foundkey = result->first;

The important thing is capturing your input

[val]
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
  • I forgot say I'm using vs 2008 for some reason, and this method won't work on that. Btw thank you, and i'm glad if you can make for 2008 vs. – Gregori Jun 02 '18 at 15:55