小编Sup*_*pAl的帖子

为什么 std::ranges::find 不能编译,而 std::find 工作正常?

考虑这段代码:

#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

c++ c++20 std-ranges

15
推荐指数
1
解决办法
1441
查看次数

标签 统计

c++ ×1

c++20 ×1

std-ranges ×1