std::ranges::all_of
Актуально для C++23.
#include <algorithm>
Актуально на 2025-05-02.
Define overload #1
template<input_iterator I, sentinel_for<I> S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {});
Вернёт true, если предикат "pred" возвратит true для каждого элемента из диапазона [first, last], иначе, false.
Example, possible implementation
Define overload #2
template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred> constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {});
Вернёт true, если предикат "pred" возвратит true для каждого элемента из последовательности "r", иначе, false.
Example, possible implementation
Notes
- Если входящая последовательность пуста, будет возвращено значение true.
- Алгоритм завершит работу как только встретится первый элемент, для которого предикат возвратит false.
- Перебор элементов начинается с начала последовательности.
Examples
Example 1:
#include <iostream> #include <algorithm> #include <vector> namespace ranges = std::ranges; int main() { std::vector<int> list = {1,2,3,4,5}; auto pred = [](auto i) { return i%2 == 0; }; bool res1 = ranges::all_of(list, pred); bool res2 = ranges::all_of(std::begin(list), std::end(list), pred); std::cout << std::boolalpha << res1 << std::endl; std::cout << res2<< std::endl; return 0; }
false false
Changelog
C++20
Введён в стандарт.See also
TODO
This page was last modified on 2025-05-02