Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guarantees on STL parallel search algorithms

Tags:

c++

stl

Do the parallel versions of search algorithms in the STL (e.g. std::find, std::find_if) guarantee to return iterators to the first element in the range matching the criterion?

The documentation makes no explicit reference to whether this is the case - and in 'C++ Concurrency in Action' there is an implementation that specifically does not return the first element.

like image 731
danielgharvey Avatar asked Oct 02 '16 08:10

danielgharvey


1 Answers

The behaviour of standard library algorithms* such as std::find, std::find_if is well specified in the C++ standard. As of C++14, there are no exceptions to the specified behaviour for parallel algorithms. This means that hypothetical parallel implementations still need to respect these requirements in order to be compliant.


* From comments, OP means the C++ standard library, and not the Standard Template Library. I make the distinction because the STL may well define a different set of rules.

like image 147
juanchopanza Avatar answered Oct 21 '22 04:10

juanchopanza