C++11- good to know algorithm
The following algorithm will make your code clean and faster
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1. std::all_of
bool res = std::all_of(std::begin(container), std::end(container), [](int value) { return value > 0; });
2. std::any_of
bool res = std::any_of(std::begin(container), std::end(container), [](int value) { return value > 0; });
3. std::none_of
bool res = std::none_of(std::begin(container), std::end(container), [](int value) { return value > 0; });
4. std::is_sorted
bool res = std::is_sorted(std::begin(container), std::end(container), [](int first, int second) { return first < second; });
5. std::is_sorted_until
auto last = std::is_sorted_until(std::begin(container), std::end(container), [](int first, int second) { return first < second; });
6. std::is_partitioned
bool res = std::is_partitioned(std::begin(container), std::end(container), [](int value) { return value > 10; });
7. std::is_permutation
bool res = std::is_permutation(std::begin(container), std::end(container), std::begin(container2);
8. std::minmax_element
std::vector<int>::iterator min, max;
std::tie(min, max) = std::minmax_element(std::begin(container), std::end(container));