Lightning talk #2 – Top STL Algorithms

lightning-talks

Lightning talk #2 – Top STL Algorithms

In this lightning talk i’m gonna write about the algorithms we should care about.

ALL STL Algorithms are important and we should know about all of them and their usage, but this topic will cover only a few of them – those that i believe that may be used more often than the others.

Accumulate

Transform

For_each

std::count

If you need to count the number of times a value is present in a collection : Use std::count

std::count_if

If you need to count the chars from a string that are lowercase

std::any_of

If you need to know if there is at least one element satisfying a predicate in a collection  : Use std::any_of.

std::all_of

If you need to know whether all the elements of a collection satisfy a given predicate, use std::all_of.

std::copy

Copy range of elements.

Copies the elements in the range [first,last) into the range beginning at result.

std::set_difference

With a sorted collection A and a sorted collection B, set_difference outputs the elements in A that are not present in B.

set_difference

Example:

Add to the cache the elements that are in the results, but that are not in the cache.

Leave a comment

Your email address will not be published.