summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libcxx/include/algorithm11
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;
}
OpenPOWER on IntegriCloud