std::map find_if condition style confusion

前端 未结 8 1055
星月不相逢
星月不相逢 2021-02-01 23:43

I\'d like to use std::find_if to search for the first element in my map that has a certain value in a specific element of its value structure. I\'m a little confus

8条回答
  •  伪装坚强ぢ
    2021-02-01 23:49

    You can use a lambda function

    int val = ...;
    auto it = std::find_if(myMap.begin(), myMap.end(), 
       [val](const std::pair & t) -> bool { 
          return t.second.x == val;
       }
    );
    

    But as Kirill V. Lyadvinsky answer suggests the "first" element may not be what you expect.

提交回复
热议问题