c++ - 将Lambda传递给std::find

标签 c++ c++11 lambda find

可能是一个深夜的挣扎,但我在这里遇到了一件简单的事情:

int main()
{
    std::vector<int> v{1,2,3,4,5 };
    int N;
    std::cin>>N;
    auto it = std::find(v.begin(), v.end(), [=](auto it)
        {
            return it*it == N;
        });
}
我只想要第一个平方为N的值,并且编译器错误:
error C2678: binary '==': no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion)
请提示我在这里想念什么?

最佳答案

您需要find_if而不是find

关于c++ - 将Lambda传递给std::find,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63876280/

相关文章:

c++ - iOS UnsafePointer 内存释放

Java : logic and operation (&&) on lambda expression allowed?

java - 从 lambda 表达式排序和子列表

c++ - 进行变换的最快方法(移动、旋转、缩放)

c++ - WM_CTLCOLORSTATIC 永远不会在 WIN32 应用程序中触发

c++ - 区分函数签名中的临时对象和非临时对象?

c++ - constexpr 函数作为数组大小

MicroVision 5.13 和 ARMCC 5.05 上的 C++11

java - 有没有一种方法/解决方法来增加 java8 中的整数

c++ - SIMD 减少 4 个 vector 而没有 hadd