std::experimental::ranges:: all_of, std::experimental::ranges:: any_of, std::experimental::ranges:: none_of
|
Определено в заголовке
<experimental/ranges/algorithm>
|
||
|
template
<
InputIterator I, Sentinel
<
I
>
S,
class
Proj
=
ranges::
identity
,
IndirectUnaryPredicate
<
projected
<
I, Proj
>>
Pred
>
|
(1) | (ranges TS) |
|
template
<
InputRange R,
class
Proj
=
ranges::
identity
,
IndirectUnaryPredicate
<
projected
<
ranges::
iterator_t
<
R
>
, Proj
>>
Pred
>
|
(2) | (ranges TS) |
|
template
<
InputIterator I, Sentinel
<
I
>
S,
class
Proj
=
ranges::
identity
,
IndirectUnaryPredicate
<
projected
<
I, Proj
>>
Pred
>
|
(3) | (ranges TS) |
|
template
<
InputRange R,
class
Proj
=
ranges::
identity
,
IndirectUnaryPredicate
<
projected
<
ranges::
iterator_t
<
R
>
, Proj
>>
Pred
>
|
(4) | (ranges TS) |
|
template
<
InputIterator I, Sentinel
<
I
>
S,
class
Proj
=
identity,
IndirectUnaryPredicate
<
projected
<
I, Proj
>>
Pred
>
|
(5) | (ranges TS) |
|
template
<
InputRange R,
class
Proj
=
ranges::
identity
,
IndirectUnaryPredicate
<
projected
<
ranges::
iterator_t
<
R
>
, Proj
>>
Pred
>
|
(6) | (ranges TS) |
[
first
,
last
)
.
[
first
,
last
)
.
[
first
,
last
)
.
Несмотря на приведенные выше объявления, фактическое количество и порядок параметров шаблона для объявлений алгоритмов не определено. Таким образом, если при вызове алгоритма используются явные аргументы шаблона, программа, вероятно, является непереносимой.
СодержаниеПараметры
Возвращаемое значение
1,2)
true
если
pred
возвращает
true
для всех элементов в диапазоне,
false
в противном случае. Возвращает
true
если диапазон пуст.
3,4)
true
если
pred
возвращает
true
хотя бы для одного элемента в диапазоне,
false
в противном случае. Возвращает
false
если диапазон пуст.
5,6)
true
если
pred
возвращает
true
ни для одного элемента в диапазоне,
false
в противном случае. Возвращает
true
если диапазон пуст.
Сложность
1-6)
Не более
last
-
first
применений предиката и
last
-
first
применений проекции.
Возможная реализация
Пример
Запустить этот код
#include <experimental/ranges/algorithm> #include <experimental/ranges/iterator> #include <functional> #include <iostream> #include <iterator> #include <numeric> #include <vector> namespace ranges = std::experimental::ranges; int main() { std::vector<int> v(10, 2); std::partial_sum(v.cbegin(), v.cend(), v.begin()); std::cout << "Among the numbers: "; ranges::copy(v, ranges::ostream_iterator<int>(std::cout, " ")); std::cout << '\n'; if (ranges::all_of(v.cbegin(), v.cend(), [](int i) { return i % 2 == 0; })) std::cout << "All numbers are even\n"; if (ranges::none_of(v, std::bind(std::modulus<int>(), std::placeholders::_1, 2))) std::cout << "None of them are odd\n"; struct DivisibleBy { const int d; DivisibleBy(int n) : d(n) {} bool operator()(int n) const { return n % d == 0; } }; if (ranges::any_of(v, DivisibleBy(7))) std::cout << "At least one number is divisible by 7\n"; } Вывод: Among the numbers: 2 4 6 8 10 12 14 16 18 20 All numbers are even None of them are odd At least one number is divisible by 7 Смотрите также
|