编译错误与 std::find_if 中的提升绑定

Compile error with boost bind in std::find_if

本文关键字:绑定 if 错误 std find 编译      更新时间:2023-10-16

请考虑以下代码片段:

#include <vector>
#include <algorithm>
#include <boost/function.hpp>
#include <boost/bind.hpp>
template<typename PODType>
class SomeClass
{
public:
    SomeClass() : m_pred(boost::bind(&SomeClass<PODType>::someMethodA, this, _1))
    {
    }
    bool someMethodA(const PODType& elem)
    {
        return false;
    }
    bool someMethodB(const std::vector<PODType>& vec)
    {
        return (std::find_if(vec.begin(), vec.end(), m_pred(_1)) != vec.end());
    }
private:
    boost::function<bool(PODType)> m_pred;
};

int main(int argc, char* argv[])
{
    SomeClass<int> obj;
    std::vector<int> v;
    obj.someMethodB(v);
    return 0;
}

编译器给出

error: no match for call to '(boost::function<bool(int)>) (boost::arg<1>&)'
note:   no known conversion for argument 1 from 'boost::arg<1>' to 'int'

对于生产线return (std::find_if(vec.begin(), vec.end(), m_pred(_1)));

我正在尝试在find_if调用的成员谓词中调用someMethodA

只需传递m_pred,无需m_pred(_1)