From ebef7459b2128e379999c3cd7f353376b5ed64bb Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Wed, 26 May 2010 18:53:44 +0000 Subject: [PATCH] [numeric.iota] git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@104719 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/numeric | 12 ++++++ .../numeric.ops/numeric.iota/iota.pass.cpp | 38 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/numerics/numeric.ops/numeric.iota/iota.pass.cpp diff --git a/include/numeric b/include/numeric index 14a6615d1..8c0bc4d37 100644 --- a/include/numeric +++ b/include/numeric @@ -50,6 +50,9 @@ template OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); +template + void iota(ForwardIterator first, ForwardIterator last, T value); + } // std */ @@ -178,6 +181,15 @@ adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterat return __result; } +template +inline _LIBCPP_INLINE_VISIBILITY +void +iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value) +{ + for (; __first != __last; ++__first, ++__value) + *__first = __value; +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_NUMERIC diff --git a/test/numerics/numeric.ops/numeric.iota/iota.pass.cpp b/test/numerics/numeric.ops/numeric.iota/iota.pass.cpp new file mode 100644 index 000000000..f6d1291f5 --- /dev/null +++ b/test/numerics/numeric.ops/numeric.iota/iota.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void iota(ForwardIterator first, ForwardIterator last, T value); + +#include +#include + +#include "../iterators.h" + +template +void +test() +{ + int ia[] = {1, 2, 3, 4, 5}; + int ir[] = {5, 6, 7, 8, 9}; + const unsigned s = sizeof(ia) / sizeof(ia[0]); + std::iota(InIter(ia), InIter(ia+s), 5); + for (unsigned i = 0; i < s; ++i) + assert(ia[i] == ir[i]); +} + +int main() +{ + test >(); + test >(); + test >(); + test(); +}