VCCC  2024.05
VisualCamp Common C++ library
for_each_n.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 1/25/24.
3 //
4 
5 #ifndef VCCC_ALGORITHM_FOR_EACH_N_HPP
6 #define VCCC_ALGORITHM_FOR_EACH_N_HPP
7 
8 #include <type_traits>
9 
11 
12 namespace vccc {
13 
16 
17 template<typename InputIt, typename Size, typename UnaryFunction>
18 constexpr InputIt for_each_n(InputIt first, Size n, UnaryFunction f) {
19  static_assert(LegacyInputIterator<InputIt>::value, "Constraints not satisfied");
20  static_assert(std::is_move_constructible<InputIt>::value, "Constraints not satisfied");
21 
22  for (Size i = 0; i < n; ++first, (void) ++i) {
23  f(*first);
24  }
25 
26  return first;
27 }
28 
30 
31 } // namespace vccc
32 
33 #endif // VCCC_ALGORITHM_FOR_EACH_N_HPP
constexpr InputIt for_each_n(InputIt first, Size n, UnaryFunction f)
Definition: for_each_n.hpp:18
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 0 > first
Definition: key_value.hpp:34
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: legacy_input_iterator.hpp:56