std::all_of
Актуально для C++23.
#include <algorithm>
Актуально на 2024-02-15.
Define overload #1
template<class InputIterator, class Predicate> constexpr inline bool all_of(InputIterator first, InputIterator last, Predicate pred);
Вернёт true, если предикат "pred" возвратит true для каждого элемента из диапазона [first, last], иначе, false.
Алгоритм завершит работу как только встретится элемент для которого предикат возвратит false. Перебор элементов начинается с позиции first*.
Example, possible implementation
Define overload #2
template <class ExecutionPolicy, class ForwardIterator, class Pred> bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Pred pred);
Example, possible implementation
Examples
Example 1:
#include <iostream>
#include <algorithm>
#include <execution>
int main()
{
const auto pred1 = [](auto el) -> bool { return el%1 == 0; };
const auto pred2 = [](auto el) -> bool { return el%2 == 0; };
auto list = {1, 2, 3, 4, 5};
auto res1 = std::all_of(std::begin(list), std::end(list), pred1);
auto res2 = std::all_of(std::begin(list), std::end(list), pred2);
std::cout << std::boolalpha;
std::cout << res1 << std::endl;
std::cout << res2 << std::endl;
return 0;
}
true false
Changelog
See also
TODO
This page was last modified on 2024-02-15