<分区>
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,
visit the help center .
关闭 9 年前 。
我知道我能做到:
vector<int> insidetest;
if(std::all_of(insidetest.begin(),insidetest.end(),[](int i){return i>100;}))
{
std::cout << "All greater" << std::endl;
}
但我想调用另一个函数(可能比 >1000 更复杂)。我如何调用 std::all_of 中的另一个函数,例如:
bool fun(const vector<int> *s)
{
return true;
}
如果 fun
有这样的签名 - 没有办法。
它有趣
有签名bool(int)
然后简单地写
if(std::all_of(insidetest.begin(),insidetest.end(),fun))
如果你想要函数中的其他参数 - 你可以使用 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)))