Does std::copy handle overlapping ranges?

后端 未结 4 2052
萌比男神i
萌比男神i 2021-01-01 14:41

When copying data from one range to another, you have to be careful if there\'s partial overlap between the source and destination ranges. If the beginning of the destinati

4条回答
  •  猫巷女王i
    2021-01-01 15:15

    It seems the most straight forward way would be to create a temporary vector of the range you want to copy:

    std::vector copiedRange( srcVecIterBegin, srcVecIterEnd);
    std::copy( copiedRange.begin(), copiedRange.end(), srcVecIterCopyLocIter);
    

    You can wrap this in a templated function that should be ably to do an overlapped using any container/iterator type.

提交回复
热议问题