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
)
내의 모든 요소에 대해 단항 predicate
pred
가
true
를 반환하는지 확인합니다.
[
first
,
last
)
내의 최소한 하나의 요소에 대해
true
를 반환하는지 확인합니다.
[
first
,
last
)
내의 어떤 요소에 대해서도
true
를 반환하지 않는지 확인합니다.
위에 기술된 선언들과는 별개로, 알고리즘 선언에 대한 실제 템플릿 매개변수의 개수와 순서는 명시되지 않습니다. 따라서 알고리즘을 호출할 때 명시적 템플릿 인수를 사용하는 경우, 해당 프로그램은 이식성이 없을 가능성이 높습니다.
목차매개변수
반환값
1,2)
true
범위 내 모든 요소에 대해
pred
가
true
를 반환하면
true
를, 그렇지 않으면
false
를 반환합니다. 범위가 비어 있는 경우
true
를 반환합니다.
3,4)
true
를 반환합니다. 만약
pred
가 범위 내의 최소한 하나의 요소에 대해
true
를 반환하는 경우, 그렇지 않으면
false
를 반환합니다. 범위가 비어 있는 경우
false
를 반환합니다.
5,6)
true
를 반환합니다 -
pred
가 범위 내 어떤 요소에 대해서도
true
를 반환하지 않는 경우,
false
를 그렇지 않은 경우에 반환합니다. 범위가 비어 있는 경우
true
를 반환합니다.
복잡도
1-6)
최대
last
-
first
번의 predicate 적용과
last
-
first
번의 projection 적용.
가능한 구현
예제
이 코드 실행
#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::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 함께 보기
|