Custom iterator works with std::sort but not with tbb::parallel_sort?

前端 未结 4 663
日久生厌
日久生厌 2021-02-15 18:13

I am trying to use tbb::parallel_sort to sort 2 arrays at the same time. Intel\'s documentation here says https://software.intel.com/en-us/node/506167 The req

4条回答
  •  一向
    一向 (楼主)
    2021-02-15 19:05

    For a RandomAccessIterator, reference must be a reference to value_type. It cannot be a tuple of references.

    As such, your dual iterator is not a valid RandomAccessIterator.

    Many algorithms will still work, but that doesn't make your code valid.

    The requirements being the same does not mean that anything that works with a given implementation of std::sort will also work with tbb::parallel_sort: a given implementation of std::sort does not have to enforce all of the requirements made in the standard.

    Regardless of the documentation, if the implementation won't work with your code, it won't work with your code.

    The easiest approach might be to create an array of pseudo-pairs of indexes (or iterators) into the original arrays, then sort it. You just need to override < properly.

提交回复
热议问题