Does std::copy handle overlapping ranges?

后端 未结 4 2031
萌比男神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条回答
  •  醉梦人生
    2021-01-01 15:22

    Preconditions for std::copy, prohibits an overlap:

    • Prototype

      template 
      OutputIterator copy(InputIterator first, InputIterator last,
                          OutputIterator result);
      
    • Preconditions

      • [first, last) is a valid range.
      • result is not an iterator within the range [first, last).
      • There is enough space to hold all of the elements being copied. More formally, the requirement is that [result, result + (last - first)) is a valid range. [1]

提交回复
热议问题