VCCC  2024.05
VisualCamp Common C++ library
for_each.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 1/10/24.
3 //
4 
5 #ifndef VCCC_ALGORITHM_RANGES_IN_FOR_EACH_HPP
6 #define VCCC_ALGORITHM_RANGES_IN_FOR_EACH_HPP
7 
8 #include <functional>
9 #include <type_traits>
10 #include <utility>
11 
18 #include "vccc/__ranges/begin.hpp"
20 #include "vccc/__ranges/end.hpp"
21 
22 namespace vccc {
23 namespace ranges {
24 
27 
28 template<typename I, typename F>
30 
31 namespace detail {
32 
33 struct for_each_niebloid {
34  template<typename I, typename S, typename Proj = identity, typename Fun, std::enable_if_t<
36  constexpr for_each_result<I, Fun>
37  operator()(I first, S last, Fun f, Proj proj = {}) const {
38  for (; first != last; ++first) {
39  vccc::invoke(f, vccc::invoke(proj, *first));
40  }
41  return {std::move(first), std::move(f)};
42  }
43 
44  template<typename R, typename Proj = identity, typename Fun, std::enable_if_t<
47  operator()(R&& r, Fun f, Proj proj = {}) const {
48  return (*this)(ranges::begin(r), ranges::end(r), std::move(f), std::ref(proj));
49  }
50 };
51 
52 } // namespace detail
53 
54 VCCC_INLINE_OR_STATIC constexpr detail::for_each_niebloid for_each{};
55 
57 
58 } // namespace ranges
59 } // namespace vccc
60 
61 #endif // VCCC_ALGORITHM_RANGES_IN_FOR_EACH_HPP
constexpr VCCC_INLINE_OR_STATIC detail::for_each_niebloid for_each
Definition: for_each.hpp:54
constexpr invoke_result_t< F, Args... > invoke(F &&f, Args &&... args) noexcept(is_nothrow_invocable< F, Args... >::value)
Definition: invoke.hpp:38
constexpr VCCC_INLINE_OR_STATIC detail::begin_niebloid begin
returns an iterator to the beginning of a range
Definition: begin.hpp:116
constexpr VCCC_INLINE_OR_STATIC detail::end_niebloid end
returns a sentinel indicating the end of a range
Definition: end.hpp:120
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
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
function object that returns its argument unchanged
Definition: identity.hpp:25
Definition: in_fun_result.hpp:22