2471. copy_n's number of InputIterator increments unspecified

Section: 28.6.1 [alg.copy] Status: LEWG Submitter: Jonathan Wakely Opened: 2015-01-28 Last modified: 2016-08-06

Priority: 3

View all other issues in [alg.copy].

View all issues with LEWG status.

Discussion:

It's unspecified how many times copy_n increments the InputIterator. uninitialized_copy_n is specified to increment it exactly n times, which means if an istream_iterator is used then the next character after those copied is read from the stream and then discarded, losing data.

I believe all three of Dinkumware, libc++ and libstdc++ implement copy_n with n - 1 increments of the InputIterator, which avoids reading and discarding a character when used with istream_iterator, but is inconsistent with uninitialized_copy_n and causes surprising behaviour with istreambuf_iterator instead, because copy_n(in, 2, copy_n(in, 2, out)) is not equivalent to copy_n(in, 4, out)

[2016-08 Chicago]

Tues PM: refer to LEWG

Proposed resolution: