Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用std::find搜索对向量时忽略其中一个值_C++ - Fatal编程技术网

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
    );