Fix copy_n to increment only n-1 times for an input iterator. This works much better with std::istream_iterator<int>(std::cin). Credit: Matan Nassau.

llvm-svn: 126581
This commit is contained in:
Howard Hinnant 2011-02-27 20:55:39 +00:00
parent 7e5fe6ce1c
commit 99847d2bf1
1 changed files with 10 additions and 1 deletions

View File

@ -1559,8 +1559,17 @@ typename enable_if
>::type
copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
{
for (; __n > 0; --__n, ++__first, ++__result)
if (__n > 0)
{
*__result = *__first;
++__result;
for (--__n; __n > 0; --__n)
{
++__first;
*__result = *__first;
++__result;
}
}
return __result;
}