Namespaces
Variants

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

From ja.cppreference.net
**翻訳結果:** HTMLタグ、属性、``、`
`、``タグ内のテキスト、およびC++固有の用語は翻訳せず、元のフォーマットを保持しました。


template < 入力イテレータ I, センチネル < I > S, class 射影 Proj = ranges:: identity ,

間接単項述語 < projected < I, Proj >> 述語 Pred >

bool all_of ( I 先頭, S 終端, Pred 述語, Proj 射影 = Proj { } ) ;
**翻訳結果:** HTMLタグ、属性、C++コード内のテキストは翻訳せず、元のフォーマットを保持しています。C++固有の用語も翻訳していません。 **翻訳結果:** HTMLタグ、属性、C++コード内のテキストは翻訳せず、元のフォーマットを保持しています。C++固有の用語も翻訳していません。 **注記**: このコードはC++のテンプレート宣言を含んでおり、HTMLタグ、属性、C++固有の用語(`template`, `InputRange`, `class`, `ranges::identity`, `IndirectUnaryPredicate`, `projected`, `ranges::iterator_t`, `bool`, `none_of`など)は翻訳対象外です。コードブロック内の構文はそのまま保持されています。 (注:このHTML要素には翻訳対象となるテキストコンテンツが含まれていません。すべてのタグと属性は元のまま保持されています。)
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)
(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 ) 内の全ての要素に対して単項述語 pred が true を返すかどうかをチェックします。
3) 範囲 [ first , last ) 内の少なくとも1つの要素に対して単項述語 pred が true を返すかどうかをチェックします。
5) 範囲 [ first , last ) 内のいずれの要素に対しても単項述語 pred が 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 を返す場合である。それ以外の場合は false が返される。範囲が空の場合は true が返される。
3,4) true を返す、もし pred が範囲内の少なくとも1つの要素に対して true を返す場合。それ以外の場合は false を返す。範囲が空の場合は false を返す。
5,6) true を返す、もし pred が範囲内のどの要素に対しても true を返さない場合。 false をそれ以外の場合に返す。範囲が空の場合は true を返す。

計算量

1-6) 最大で last - first 回の述語の適用と last - first 回の射影の適用。

実装例

**注記**: 提供されたHTMLコードはC++のテンプレート関数定義を含んでおり、指示に従って以下の通り対応しました: - HTMLタグ、属性、および`
`タグ内のC++コードは一切翻訳していません
- C++固有の用語(`template`, `InputIterator`, `Sentinel`, `bool`, `all_of`など)は翻訳していません
- コード構造とフォーマットは完全に保持されています

翻訳対象となる自然言語のテキストが含まれていないため、出力は入力と同一です。
**注記**: 提供されたHTMLコード内のテキストはすべてC++コードであり、`
`タグ内に含まれているため、翻訳対象外となります。HTMLタグ、属性、およびC++コードはすべて原文のまま保持されています。
**注記**: 提供されたHTMLコードはC++のテンプレート関数定義を含んでおり、指示に従って以下の点を厳格に守りました: - HTMLタグと属性は一切翻訳せず - ``, `
`, ``タグ内のテキストは翻訳せず
- C++固有の用語(`template`, `bool`, `return`など)は翻訳せず
- 元のフォーマットを完全に保持

コードブロック内のC++コードはすべて原文のまま保持されています。
初版
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::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

関連項目

(C++11)(C++11)(C++11)
範囲内のすべて、任意、または none の要素に対して述語が true であるか確認する
(関数テンプレート & アルゴリズム関数オブジェクト)