C++11- good to know algorithm

The following algorithm will make your code clean and faster

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));

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s