Re: copy_n should result in a one past the end input iterator
On 21/11/16 03:10 +, Robert Young wrote: /* gcc -Wall -Wextra -std=c++11 copy_n_vs_copy.cpp -lstdc++ -o copy_n_vs_copy One Past the End https://gcc.gnu.org/onlinedocs/libstdc++/manual/iterators.html#iterators.predefined.end BUG location: /usr/lib/gcc/x86_64-pc-linux-gnu/5.1.0/include/g++-v5/bits/stl_algo.h */ Hi, This mailing list is for automated email from our Bugzilla database, if you send email to this list it is likely to be missed or ignored. Please report bugs to Bugzilla as described at https://gcc.gnu.org/bugs/ However, this is not a bug because it is unclear what the right behaviour is for this algorithm, see http://cplusplus.github.io/LWG/lwg-active.html#2471 We are not going to change libstdc++ until the C++ standards committee decides what the right behaviour is.
copy_n should result in a one past the end input iterator
/* gcc -Wall -Wextra -std=c++11 copy_n_vs_copy.cpp -lstdc++ -o copy_n_vs_copy One Past the End https://gcc.gnu.org/onlinedocs/libstdc++/manual/iterators.html#iterators.predefined.end BUG location: /usr/lib/gcc/x86_64-pc-linux-gnu/5.1.0/include/g++-v5/bits/stl_algo.h */ #include #include #include #include int main() { std::string i("abc"); std::string o; std::istringstream t; t=std::istringstream(i); o.clear(); assert(3==t.rdbuf()->in_avail()); std::copy(std::istreambuf_iterator(t.rdbuf()), std::istreambuf_iterator(),back_inserter(o)); std::cout<<"Test1(copy):\tResult_size:"in_avail()); std::copy_n(std::istreambuf_iterator(t.rdbuf()), 3,back_inserter(o)); std::cout<<"Test2(copy_n):\tResult_size:" 0) - ++__first; - else + ++__first; + if (--__n <= 0) break; } }