diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-29 16:26:10 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-29 16:26:10 +0000 |
commit | b276b1db48faa7328575ab722fe3bc340623f025 (patch) | |
tree | 9e4ba424f754c3f05e409ae647fa358031d97617 /include/algorithm | |
parent | d1bd27794dfbc317e27d1ec63b338115cbf194ba (diff) |
Notes
Diffstat (limited to 'include/algorithm')
-rw-r--r-- | include/algorithm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/algorithm b/include/algorithm index 08ca23ff6168..7ea4474a1bb4 100644 --- a/include/algorithm +++ b/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,26 @@ for_each(_InputIterator __first, _InputIterator __last, _Function __f) return __f; } +#if _LIBCPP_STD_VER > 14 +// 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; +} +#endif + // find template <class _InputIterator, class _Tp> |