Are parallel STL algorithms compliant with a std::back_insert_iterator
??
I might be misinterpreting the difference between std::par
and std::par_vec
, does std::par_vec
mean that the output range is required to be pre-allocated?
Code example:
auto numbers = {1,2,3,4,5,6};
auto squared = std::vector<int>{};
std::transform(
**std::par/std::par_vec,**
numbers.begin(),
numbers.end(),
std::back_inserter(squared),
[](auto val) {
return val*val;
}
);
Update
Simplified questions as my first question was a result of misreading an article.
Are parallel STL algorithms compliant with a std::back_insert_iterator??
N4659 specifies (28.6.4) as follows.
The older, pre-execution-policy, overload of std::transform
, uses input iterators and output iterators.
template<class InputIterator, class OutputIterator, class UnaryOperation>
OutputIterator transform(InputIterator first, InputIterator last,
OutputIterator result, UnaryOperation op);
the newer overload, using execution policies, uses forward iterators:
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class UnaryOperation>
ForwardIterator2 transform(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, UnaryOperation op);
So it seems like you can't use back_insert_iterator
with the new overload, as it doesn't meet the forward iterators concept requirements.
does std::par_vec mean that the output range is required to be pre-allocated?
std::par_vec
refers to vectorization in the sense of vectorization vs. parallelization. It specifies that both can be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With