empty | all true | all false | mixed | |
---|---|---|---|---|
all_of | true | true | false | false |
any_of | false | true | false | true |
none_of | true | false | true | false |
- 処理結果に迷う時がある(特に空の時)ので、表にして整理してみました。
Note
- all_of,any_of,none_of は相互に書き換え可能。(i.e. 以下の3つの式は同等。)
all_of( ary, func ) ;
none_of( ary, not_fn( func ) ) ;
!any_of( ary, not_fn( func ) ) ;
- 条件を満たす物の個数に着目すると、空の時の結果が分かりやすい(かも)。
- i.e.
all_of( ary, func ) ;
はcount_if( ary, func ) == ary.size() ;
と同等。 1
- i.e.
- boost の
boost::algorithm::all_of
及び C++20 のstd::ranges::all_of
を使うと、
イテレータで無く配列などを、引数へ与える事が出来る。 - boost に、似た名前の one_of という関数が有るが、これは別物なので注意。
- 条件を満たす要素の個数が、唯1つのみの時に、true を返す。
参照
C++日本語リファレンス
- https://cpprefjp.github.io/reference/algorithm/all_of.html
- https://cpprefjp.github.io/reference/algorithm/none_of.html
- https://cpprefjp.github.io/reference/algorithm/any_of.html
-
実行効率には差異が出る事に留意。 ↩