在std :: all_of中调用一个函数

Avr*_*dis 1 c++ stl c++11

我知道我可以这样做:

 vector<int> insidetest;

 if(std::all_of(insidetest.begin(),insidetest.end(),[](int i){return i>100;}))
    {
       std::cout << "All greater" << std::endl;
    }
Run Code Online (Sandbox Code Playgroud)

但我想调用另一个函数(可能比仅仅> 1000更复杂).如何在std :: all_of中调用另一个函数,例如:

   bool fun(const vector<int> *s)
   {
   return true;
   }
Run Code Online (Sandbox Code Playgroud)

For*_*veR 8

如果fun有这样的签名 - 没有办法.它fun有签名bool(int)然后简单写

if(std::all_of(insidetest.begin(),insidetest.end(),fun))
Run Code Online (Sandbox Code Playgroud)

如果你想在函数中使用其他参数 - 你可以使用std::bind 例如签名bool(int, int, int)

bool fun(int value, int min, int max)
{
   return value > min && value < max;
}

if(std::all_of(insidetest.begin(),insidetest.end(),
               std::bind(fun, std::placeholders::_1, 1, 5)))
Run Code Online (Sandbox Code Playgroud)