concept std::find in category c++

appears as: std::find
C++ Concurrency in Action, Second Edition

This is an excerpt from Manning's book C++ Concurrency in Action, Second Edition.

8.5.2. A parallel implementation of std::find

std::find is a useful algorithm to consider next because it’s one of several algorithms that can complete without every element having been processed. For example, if the first element in the range matches the search criterion, there’s no need to examine any other elements. As you’ll see shortly, this is an important property for performance, and it has direct consequences for the design of the parallel implementation. It’s a particular example of how data access patterns can affect the design of your code (section 8.3.2). Other algorithms in this category include std::equal and std::any_of.

If you and your partner were searching for an old photograph through the boxes of keepsakes in your attic, you wouldn’t let them continue searching if you found the photograph. Instead, you’d let them know you’d found the photograph (perhaps by shouting, “Found it!”), so that they could stop searching and move on to something else. The nature of many algorithms requires that they process every element, so they have no equivalent to shouting, “Found it!” For algorithms such as std::find, the ability to complete “early” is an important property and not something to squander. You therefore need to design your code to make use of it—to interrupt the other tasks in some way when the answer is known, so that the code doesn’t have to wait for the other worker threads to process the remaining elements.