diff options
author | Howard Hinnant <hhinnant@apple.com> | 2011-02-27 20:55:39 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2011-02-27 20:55:39 +0000 |
commit | 99847d2bf132854fffa019bab19818768102ccad (patch) | |
tree | 03bdc6eeb5afb314009d2c54c06b1ef50dece30e /libcxx/include/algorithm | |
parent | 7e5fe6ce1c953ae92c441fffa71645850adb2783 (diff) | |
download | bcm5719-llvm-99847d2bf132854fffa019bab19818768102ccad.tar.gz bcm5719-llvm-99847d2bf132854fffa019bab19818768102ccad.zip |
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
Diffstat (limited to 'libcxx/include/algorithm')
-rw-r--r-- | libcxx/include/algorithm | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index d91c57c1109..4909221bb09 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -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; } |