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
를 반환하지 않는지 확인합니다.
위에 기술된 선언들과는 별개로, 알고리즘 선언에 대한 실제 템플릿 매개변수의 개수와 순서는 명시되지 않습니다. 따라서 알고리즘을 호출할 때 명시적 템플릿 인수를 사용하는 경우, 해당 프로그램은 이식성이 없을 가능성이 높습니다.
목차 |
매개변수
| first, last | - | 검사할 요소들의 범위 |
| r | - | 검사할 요소들의 범위 |
| pred | - | 투영된 요소들에 적용할 조건자 |
| proj | - | 요소들에 적용할 투영 |
반환값
복잡도
가능한 구현
| 첫 번째 버전 |
|---|
template<InputIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> bool all_of(I first, S last, Pred pred, Proj proj = Proj{}) { return ranges::find_if_not(first, last, std::ref(pred), std::ref(proj)) == last; } template<InputRange R, class Proj = ranges::identity, IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred> bool all_of(R&& r, Pred pred, Proj proj = Proj{}) { return ranges::all_of(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj)); } |
| 두 번째 버전 |
template<InputIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> bool any_of(I first, S last, Pred pred, Proj proj = Proj{}) { return ranges::find_if(first, last, std::ref(pred), std::ref(proj)) != last; } template<InputRange R, class Proj = ranges::identity, IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred> bool any_of(R&& r, Pred pred, Proj proj = Proj{}) { return ranges::any_of(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj)); } |
| 세 번째 버전 |
template<InputIterator I, Sentinel<I> S, class Proj = identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> bool none_of(I first, S last, Pred pred, Proj proj = Proj{}) { return ranges::find_if(first, last, std::ref(pred), std::ref(proj)) == last; } template<InputRange R, class Proj = ranges::identity, IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred> bool none_of(R&& r, Pred pred, Proj proj = Proj{}) { return ranges::none_of(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj)); } |
예제
#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
참고 항목
|
(C++11)
(C++11)
(C++11)
|
범위 내의 모든 요소, 어떤 요소, 또는 어떤 요소도 서술어가
true
인지 확인합니다
(함수 템플릿) |