ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.06k stars 437 forks source link

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

Open TheThief opened 2 years ago

TheThief commented 2 years ago

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);