std::experimental::ranges:: all_of, std::experimental::ranges:: any_of, std::experimental::ranges:: none_of
|
Definiert im Header
<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
)
true
zurückgibt.
[
first
,
last
)
true
zurückgibt.
[
first
,
last
)
true
zurückgibt.
Ungeachtet der oben dargestellten Deklarationen sind die tatsächliche Anzahl und Reihenfolge der Template-Parameter für Algorithmusdeklarationen nicht spezifiziert. Daher ist ein Programm wahrscheinlich nicht portabel, wenn explizite Template-Argumente beim Aufruf eines Algorithmus verwendet werden.
InhaltParameter
Rückgabewert
1,2)
true
wenn
pred
für alle Elemente im Bereich
true
zurückgibt,
false
andernfalls. Gibt
true
zurück, wenn der Bereich leer ist.
3,4)
true
falls
pred
für mindestens ein Element im Bereich
true
zurückgibt,
false
andernfalls. Gibt
false
zurück, falls der Bereich leer ist.
5,6)
true
wenn
pred
für keine Elemente im Bereich
true
zurückgibt,
false
andernfalls. Gibt
true
zurück, wenn der Bereich leer ist.
Komplexität
1-6)
Höchstens
last
-
first
Anwendungen des Prädikats und
last
-
first
Anwendungen der Projektion.
Mögliche Implementierung
Beispiel
Diesen Code ausführen
#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 << "Unter den Zahlen: "; 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 << "Alle Zahlen sind gerade\n"; if (ranges::none_of(v, std::bind(std::modulus<int>(), std::placeholders::_1, 2))) std::cout << "Keine davon ist ungerade\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 << "Mindestens eine Zahl ist durch 7 teilbar\n"; } Ausgabe: Unter den Zahlen: 2 4 6 8 10 12 14 16 18 20 Alle Zahlen sind gerade Keine davon ist ungerade Mindestens eine Zahl ist durch 7 teilbar Siehe auch
|