concept algorithm in category c++

This is an excerpt from Manning's book C++ Concurrency in Action, Second Edition.
In the final queue example, you saw how a thread performing a push operation had to wait for another thread also performing a push to complete its operation before it could proceed. Left alone, this would have been a busy-wait loop, with the waiting thread wasting CPU time while failing to proceed. If you end up with a busy-wait loop, you effectively have a blocking operation and might as well use mutexes and locks. By modifying the algorithm so that the waiting thread performs the incomplete steps if it’s scheduled to run before the original thread completes the operation, you can remove the busy-wait and the operation is no longer blocking. In the queue example this required changing a data member to be an atomic variable rather than a non-atomic variable and using compare/exchange operations to set it, but in more complex data structures it might require more extensive changes.
Before we get onto the algorithms themselves, let’s take a look at the execution policies.
In this chapter we looked at the parallel algorithms available in the C++ Standard Library and how to use them. We looked at the various execution policies, the impact your choice of execution policy has on the behavior of the algorithm, and the restrictions it imposes on your code. We then looked at an example of how this algorithm might be used in real code.

This is an excerpt from Manning's book Functional Programming in C++.
We started talking about FP style by considering an imperative implementation of an algorithm that counts newlines in a collection of files. The function that counts newlines should always return the same array of integers when invoked over the same list of files (provided the files weren’t changed by an external entity). This means the function could be implemented as a pure function.
The truth is, after you look behind the curtain, there’s no magic—just simple concepts with big consequences. The first simple yet far-reaching concept we used in the previous chapter is the ability to pass one function as an argument to an algorithm from the Standard Template Library (STL). The algorithms in the STL are applicable to a multitude of problems mainly because you can customize their behavior.
STL doesn’t have functions to remove the whitespace from the beginning and the end of a string. But it does provide algorithms you can use to implement something like this.
The algorithm you need is
std::find_if. It searches for the first item in the collection that satisfies the specified predicate. In this case, you’re going to search for the first character in the string that isn’t whitespace. The algorithm returns the iterator pointing to the first element in the string that satisfies the predicate. It’s sufficient to remove all elements from the beginning up to that element, thus stripping the whitespace from the start of the string:std::string trim_left(std::string s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), is_not_space)); return s; }As usual, the algorithm takes a pair of iterators to define the collection. If you pass it the reverse iterators, it’ll search from the end toward the beginning of the string. This way, you can trim the whitespace from the right: