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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@126581 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
df85e57f4a
commit
171869e27c
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user