简体   繁体   English

具有重叠范围的 std::unique_copy

[英]std::unique_copy with overlapping ranges

template< class InputIt, class OutputIt >
OutputIt unique_copy( InputIt first, InputIt last,
                      OutputIt d_first );

Is it valid to use std::unique_copy if input range and output range overlap?如果输入范围和 output 范围重叠,使用std::unique_copy是否有效? Consider the following two example cases考虑以下两个示例案例

auto d_last = std::unique_copy(first, last, d_first);

  1. d_first <= first <= d_last <= last
  2. first <= d_first <= last <= d_last

The preconditions for std::unique_copy are described in [algorithms#alg.unique-8] : [algorithms#alg.unique-8]中描述了std::unique_copy的先决条件:

 template<class InputIterator, class OutputIterator> constexpr OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result);

Preconditions :先决条件

  • The ranges [first, last) and [result, result+(last-first)) do not overlap.范围[first, last)[result, result+(last-first))不重叠。

So this is undefined behavior.所以这是未定义的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM