range-v3 icon indicating copy to clipboard operation
range-v3 copied to clipboard

extra increment on ranges::copy_n compared to other standard implementations

Open TheThief opened this issue 3 years ago • 0 comments

See also: https://cplusplus.github.io/LWG/issue2471

The extra trailing increment on ranges::copy_n causes trouble when you use it with an istream_iterator source, as istream_iterator performs an irreversible action on increment.

Essentially, this will consume 6 ints from the source stream, instead of 5:

ranges::copy_n(std::istream_iterator<int>(is), 5, dest);

A similar issue exists with copy, take, and istream_view - the following will consume 6 ints from the source stream also:

ranges::copy(ranges::istream_view<int>(is) | views::take(5), dest);

TheThief avatar Dec 07 '21 19:12 TheThief