C++ 使用std::find搜索对向量时忽略其中一个值
在给定的成对向量中C++ 使用std::find搜索对向量时忽略其中一个值,c++,C++,在给定的成对向量中 static std::vector<std::pair<int,int>> v 使用更好的算法:: 使用find\u如果,则可以根据需要进行比较。 std::find(v.begin(), v.end(), std::make_pair(first int, /*ignored value*/)) - v.begin(); auto it = std::find_if(v.begin(), v.end(), [first](const std::
static std::vector<std::pair<int,int>> v
使用更好的算法::
使用
find\u如果
,则可以根据需要进行比较。
std::find(v.begin(), v.end(), std::make_pair(first int, /*ignored value*/)) - v.begin();
auto it = std::find_if(v.begin(), v.end(), [first](const std::pair<int, int>& elem){
return elem.first == first;
});
auto it = ranges::find(v,
first, // the value
&std::pair<int, int>::first // the projection
);