ranges::all_of / any_of / none_of
ranges::all_of / any_of / none_of (범위 조건 검사)
범위의 원소들이 단항 술어를 모두/하나라도/전혀 만족하는지 검사하는 ranges 버전 알고리즘들이에요. <algorithm> 헤더에 있어요.
출처: cppreference
본문
std::ranges::all_of, any_of, none_of는 각각 "모두", "적어도 하나", "하나도" 술어를 만족하는지 검사해요. 범위 객체를 받아요.
namespace std::ranges {
template< std::input_iterator I, std::sentinel_for<I> S,
class Proj = std::identity,
std::indirect_unary_predicate<std::projected<I, Proj>> Pred >
constexpr bool all_of( I first, S last, Pred pred, Proj proj = {} );
}
all_of: 모든 원소가pred를 만족하면true.any_of: 적어도 하나가 만족하면true.none_of: 어떤 원소도 만족하지 않으면true.proj는 요소에 적용할 투영 함수예요(선택).
빈 범위에서 all_of와 none_of는 true, any_of는 false를 반환해요(논리 규칙).
std::vector<int> v{2, 4, 6};
bool all_even = std::ranges::all_of(v, [](int x){ return x % 2 == 0; }); // true
반복자 버전 std::all_of 등을 범위 중심으로 다시 만든 것이에요.