[cfe-commits] [libcxx] r126581 - /libcxx/trunk/include/algorithm
Howard Hinnant
hhinnant at apple.com
Sun Feb 27 12:55:39 PST 2011
Author: hhinnant
Date: Sun Feb 27 14:55:39 2011
New Revision: 126581
URL: http://llvm.org/viewvc/llvm-project?rev=126581&view=rev
Log:
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.
Modified:
libcxx/trunk/include/algorithm
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=126581&r1=126580&r2=126581&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Sun Feb 27 14:55:39 2011
@@ -1559,8 +1559,17 @@
>::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;
}
More information about the cfe-commits
mailing list