forked from OSchip/llvm-project
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:
parent
7e5fe6ce1c
commit
99847d2bf1
|
@ -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…
Reference in New Issue