std::map find_if condition style confusion

前端 未结 8 1063
星月不相逢
星月不相逢 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-02 00:12

    For the lazy, use a C++17 auto lambda, then you don't need to be verbose with the type.

    const auto it = std::find_if(myMap.begin(), myMap.end(), [&val](const auto &it) { 
          return it.second.x == val; // Comparing with the object
       }
    );
    

提交回复
热议问题