[C++] all_of, any_of, none_of
Updated:
개요
- all_of
- 범위가 비었거나 모두 참이면 true 반환
- any_of
- 범위 요소중 하나라도 참이면 true 반환
- none_of
- 범위가 비었거나 모두 거짓이면 true 반환
예제
- 코드
#include <algorithm> #include <cstdlib> #include <iostream> #include <vector> using namespace std; int main() { auto func = [](vector<int> v, auto f) { cout << all_of(v.cbegin(), v.cend(), f) << endl; cout << any_of(v.cbegin(), v.cend(), f) << endl; cout << none_of(v.cbegin(), v.cend(), f) << endl; }; func({}, [](int i) { return true; }); cout << "------ 1" << endl; func({1, 2, 3}, [](int i) { return i > 0 ? true : false; }); cout << "------ 2" << endl; func({1, 2, 3}, [](int i) { return i < 0 ? true : false; }); cout << "------ 3" << endl; func({1, 2, 3}, [](int i) { return i > 2 ? true : false; }); return EXIT_SUCCESS; }
- 실행 결과
1 0 1 ------ 1 1 1 0 ------ 2 0 0 1 ------ 3 0 1 0