Kle*_*rič 29 c++ stl language-lawyer c++11
鉴于以下代码,
std::vector<int> numbers = {1, 2, 3, 4, 5};
std::any_of(std::begin(numbers), std::end(numbers),
[](int number) { return number > 3; } );
Run Code Online (Sandbox Code Playgroud)
std :: any_of需要(按标准),一旦达到4就返回?
Sto*_*ica 33
标准本身并没有提出任何这样的硬性要求.但有人可能会推断它是间接鼓励的([alg.any_of]):
Run Code Online (Sandbox Code Playgroud)template <class InputIterator, class Predicate> bool any_of(InputIterator first, InputIterator last, Predicate pred); template <class ExecutionPolicy, class ForwardIterator, class Predicate> bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);返回:如果[first,last]为空,或者如果在[first,last]范围内没有迭代器i使得pred(*i)为真,则返回false,否则返回true.
复杂性:最多 - 谓词的最后一次应用.
虽然一个完全符合要求的实现可能会准确地 应用谓词last-first,但对我来说,这句话听起来似乎会被鼓励尽快退出.
请注意,几乎不可能要求接受相同的过载ExecutionPolicy.从那以后,评估的顺序是未知的.
在一个不那么正式的说明中,顺序版本的任何实现都不会在谓词为真的情况下退出,这会使其作者的凭据受到质疑.