diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-05-25 02:29:54 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-05-25 02:29:54 +0000 |
commit | d5c65ffa8dd419b618b1c28602637d3e816d8a94 (patch) | |
tree | 229d2b9b70ebc54ccec1f113574b1f916faa085c /libcxx/include/algorithm | |
parent | d2a7e8538b9c6de35759c28c3e3df8419680d08e (diff) | |
download | bcm5719-llvm-d5c65ffa8dd419b618b1c28602637d3e816d8a94.tar.gz bcm5719-llvm-d5c65ffa8dd419b618b1c28602637d3e816d8a94.zip |
Add non-parallel version of for_each_n (+tests) from the Parallelism TS
llvm-svn: 303833
Diffstat (limited to 'libcxx/include/algorithm')
-rw-r--r-- | libcxx/include/algorithm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index 08ca23ff616..168d2c442aa 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -35,6 +35,9 @@ template <class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function f); +template<class InputIterator, class Size, class Function> + InputIterator for_each_n(InputIterator first, Size n, Function f); // C++17 + template <class InputIterator, class T> InputIterator find(InputIterator first, InputIterator last, const T& value); @@ -961,6 +964,24 @@ for_each(_InputIterator __first, _InputIterator __last, _Function __f) return __f; } +// for_each_n + +template <class _InputIterator, class _Size, class _Function> +inline _LIBCPP_INLINE_VISIBILITY +_InputIterator +for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) +{ + typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; + _IntegralSize __n = __orig_n; + while (__n > 0) + { + __f(*__first); + ++__first; + --__n; + } + return __first; +} + // find template <class _InputIterator, class _Tp> |