考虑这段代码:
#include <vector>
#include <iostream>
#include <cstdint>
#include <ranges>
int main()
{
struct S {
int a;
int b;
bool operator==(int other) const { return a == other; }
};
std::vector<S> iv{
{1, 2},
{3, 4}
};
// this works
if (auto const it{std::find(iv.begin(), iv.end(), 1)}; it != iv.end()) {
std::cout << "Found!\n" << "\n";
}
//std::ranges::find(iv, 2); // <-- why does this not compile
}
Run Code Online (Sandbox Code Playgroud)
我的印象是范围的调用约定将是相应原始算法的一对一映射(即,只需跳过 and .begin(),.end()它应该像以前一样工作)。
显然这里的情况并非如此。我缺少什么?
代码链接: https: //godbolt.org/z/3a6z9c5of