Namespaces
Variants

std::experimental::ranges:: all_of, std::experimental::ranges:: any_of, std::experimental::ranges:: none_of

From cppreference.net
헤더 파일에 정의됨 <experimental/ranges/algorithm>
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 { } ) ;
(1) (ranges TS)
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 { } ) ;
(2) (ranges TS)
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 { } ) ;
(3) (ranges TS)
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 { } ) ;
(4) (ranges TS)
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 { } ) ;
(5) (ranges TS)
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 { } ) ;
(6) (ranges TS)
1) 범위 [ first , last ) 내의 모든 요소에 대해 단항 predicate pred true 를 반환하는지 확인합니다.
3) 단항 술어 pred 가 범위 [ first , last ) 내의 최소한 하나의 요소에 대해 true 를 반환하는지 확인합니다.
5) 단항 술어 pred 가 범위 [ first , last ) 내의 어떤 요소에 대해서도 true 를 반환하지 않는지 확인합니다.
2,4,6) (1,3,5) 와 동일하지만, r 를 소스 범위로 사용하며, 마치 ranges:: begin ( r ) first 로, ranges:: end ( r ) last 로 사용하는 것과 같습니다.

위에 기술된 선언들과는 별개로, 알고리즘 선언에 대한 실제 템플릿 매개변수의 개수와 순서는 명시되지 않습니다. 따라서 알고리즘을 호출할 때 명시적 템플릿 인수를 사용하는 경우, 해당 프로그램은 이식성이 없을 가능성이 높습니다.

목차

매개변수

first, last - 검사할 요소들의 범위
r - 검사할 요소들의 범위
pred - 투영된 요소들에 적용할 조건자
proj - 요소들에 적용할 투영

반환값

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 적용.

가능한 구현

첫 번째 버전
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 인지 확인합니다
(함수 템플릿)