Is it valid to use std::transform with std::back_inserter?

前端 未结 4 1365
北恋
北恋 2021-02-18 13:56

Cppreference has this example code for std::transform:

std::vector ordinals;
std::transform(s.begin(), s.end(), std::back_inserter(ordinals),
         


        
4条回答
  •  忘掉有多难
    2021-02-18 14:37

    So the thing I missed is that the parallel versions take LegacyForwardIterators, not LegacyOutputIterator. A LegacyForwardIterator can be incremented without invalidating copies of it, so it is easy to use this to implement an out-of-order parallel std::transform.

    I think the non-parallel versions of std::transform must be executed in-order. Either cppreference is wrong about it, or possibly the standard just leaves this requirement implicit because there is no other way to implement it. (Shotgun not wading through the standard to find out!)

提交回复
热议问题