This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/64814] std::copy_n advances InputIterator one *less* time than necessary.
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 27 Jan 2015 16:06:03 +0000
- Subject: [Bug libstdc++/64814] std::copy_n advances InputIterator one *less* time than necessary.
- Auto-submitted: auto-generated
- References: <bug-64814-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64814
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think the behaviour you're seeing is correct (and Clang gives the same
result). The problem is that increments to the input iterator happen inside the
copy_n call, to a copy of the iterator not to readIter itself. This means it is
not equivalent to your for (int j = 0; j < 4; ++j) loop which operates directly
on readIter.
Each time through the outer loop the readIter variable has not been
incremented, so has not cached the next element from the input stream.