Can I use std::tranform in place with a parallel execution policy?

G

geo

Guest
If I am not mistaken, I can make std::transform perform in place by using the same range as an input and output iterator. Assume I have some std::vector object vec, then I would write

std::transform(vec.cbegin(),vec.cend(),vec.begin(),unary_op)


using a suitable unary operation unary_op.

Using the C++17 standard, I would like to execute the transform in parallel by sticking an std::execution::par in there as the first argument. This would make the function go from overload (1) to (2) in the cppreference article on std::transform. However the comments to this overload says:

unary_op [...] must not invalidate any iterators, including the end iterators, or modify any elements of the ranges involved. (since C++11)
Does "modify any elements" really mean I cannot use the algorithm in place or is this talking about a different detail that I misinterpreted?

Thank you.

Continue reading...
 
Top