GeezerVison is showing cpprefjp.github.io — std::ranges::any_of - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function template
<algorithm>
std::ranges:: any_of (C++20)
namespace std :: ranges {
template < input_iterator I ,
sentinel_for < I > S ,
class Proj = identity ,
indirect_unary_predicate < projected < I , Proj >> Pred >
constexpr bool
any_of ( I first , S last , Pred pred , Proj proj = {}); // (1) C++20
template < input_range R ,
class Proj = identity ,
indirect_unary_predicate < projected < iterator_t < R > , Proj >> Pred >
constexpr bool
any_of ( R && r , Pred pred , Proj proj = {}); // (2) C++20
template < execution-policy Ep ,
random_access_iterator I ,
sized_sentinel_for < I > S ,
class Proj = identity ,
indirect_unary_predicate < projected < I , Proj >> Pred >
bool any_of ( Ep && exec ,
I first ,
S last ,
Pred pred ,
Proj proj = {}); // (3) C++26
template < execution-policy Ep ,
sized-random-access-range R ,
class Proj = identity ,
indirect_unary_predicate < projected < iterator_t < R > , Proj >> Pred >
bool any_of ( Ep && exec ,
R && r ,
Pred pred ,
Proj proj = {}); // (4) C++26
}
概要
範囲のいずれかの要素が条件を満たすかを判定する。
(1): イテレータ範囲を指定する
(2): Rangeを直接指定する
(3): (1)の並列アルゴリズム版。実行ポリシーを指定する
(4): (2)の並列アルゴリズム版。実行ポリシーを指定する
テンプレートパラメータ制約
戻り値
[first,last) あるいは r 内のイテレータ i について invoke (pred, invoke (proj, *i)) が true になるような要素があればtrueを返し、そうでなければfalseを返す。
[first,last) あるいは r の範囲が空の場合はfalseを返す。
計算量
最大で last - first 回 pred を実行する。
例
基本的な使い方
出力
false
true
並列アルゴリズムの例 (C++26)
出力
true
実装例
struct any_of_impl {
template < input_iterator I , sentinel_for < I > S , class Proj = identity , indirect_unary_predicate < projected < I , Proj >> Pred >
constexpr bool operator ()( I first , S last , Pred pred , Proj proj = {}) const {
for ( ; first != last ; ++ first )
if ( invoke ( pred , invoke ( proj , * first ))) return true ;
return false ;
}
template < input_range R , class Proj = identity , indirect_unary_predicate < projected < iterator_t < R > , Proj >> Pred >
constexpr bool operator ()( R && r , Pred pred , Proj proj = {}) const {
return ( * this )( begin ( r ), end ( r ), ref ( pred ), ref ( proj ));
}
};
inline constexpr any_of_impl any_of ;
バージョン
言語
処理系
関連項目
参照