From ca6ba120b35012c5092bf5af1e7228926bbe4b29 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 7 Oct 2017 17:04:01 +0900 Subject: [PATCH] add for_each_n algorithm --- sprout/algorithm/cxx14.hpp | 1 + sprout/algorithm/cxx14/for_each_n.hpp | 28 +++++++++++++++++++++++++++ sprout/algorithm/for_each_n.hpp | 14 ++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 sprout/algorithm/cxx14/for_each_n.hpp create mode 100644 sprout/algorithm/for_each_n.hpp diff --git a/sprout/algorithm/cxx14.hpp b/sprout/algorithm/cxx14.hpp index 532111cb..69d180cd 100644 --- a/sprout/algorithm/cxx14.hpp +++ b/sprout/algorithm/cxx14.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff --git a/sprout/algorithm/cxx14/for_each_n.hpp b/sprout/algorithm/cxx14/for_each_n.hpp new file mode 100644 index 00000000..c52ce7a2 --- /dev/null +++ b/sprout/algorithm/cxx14/for_each_n.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_ALGORITHM_CXX14_FOR_EACH_N_HPP +#define SPROUT_ALGORITHM_CXX14_FOR_EACH_N_HPP + +#include +#include + +namespace sprout { + // + // 25.2.4 For each + // + template + inline SPROUT_CXX14_CONSTEXPR InputIterator + for_each_n(InputIterator first, Size n, Function f) { + for (Size i = 0; i < n; ++first) { + f(*first); + } + return first; + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_CXX14_FOR_EACH_N_HPP diff --git a/sprout/algorithm/for_each_n.hpp b/sprout/algorithm/for_each_n.hpp new file mode 100644 index 00000000..f1d9d4a1 --- /dev/null +++ b/sprout/algorithm/for_each_n.hpp @@ -0,0 +1,14 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_ALGORITHM_FOR_EACH_N_HPP +#define SPROUT_ALGORITHM_FOR_EACH_N_HPP + +#include +#include + +#endif // #ifndef SPROUT_ALGORITHM_FOR_EACH_N_HPP