VCCC  2024.05
VisualCamp Common C++ library
all.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 2023/12/29.
3 //
4 
5 #ifndef VCCC_RANGES_VIEWS_ALL_HPP
6 #define VCCC_RANGES_VIEWS_ALL_HPP
7 
8 #include <type_traits>
9 #include <utility>
10 
13 #include "vccc/__ranges/range.hpp"
16 #include "vccc/__ranges/view.hpp"
20 
21 namespace vccc {
22 namespace ranges {
23 namespace views {
24 namespace detail {
25 
26 using vccc::detail::return_category;
27 
28 class all_adaptor_closure : public range_adaptor_closure<all_adaptor_closure> {
29  template<typename T>
30  using return_category_type =
31  std::conditional_t<
32  view<std::decay_t<T>>::value, return_category<1, std::decay_t<T>>,
33  std::conditional_t<
36  std::is_object<std::remove_reference_t<T>>,
37  std::is_lvalue_reference<T>
38  >::value,
39  return_category<2, ref_view<std::remove_reference_t<T>>>,
40  return_category<3, owning_view<std::remove_reference_t<T>>>
41  >>;
42 
43  template<typename R, typename T>
44  constexpr T operator()(R&& r, return_category<1, T>) const {
45  return std::forward<R>(r);
46  }
47 
48  template<typename R, typename T>
49  constexpr T operator()(R&& r, return_category<2, T>) const {
50  return {std::forward<R>(r)}; // ref_view
51  }
52 
53  template<typename R, typename T>
54  constexpr T operator()(R&& r, return_category<3, T>) const {
55  return {std::forward<R>(r)}; // owning_view
56  }
57 
58  public:
59  all_adaptor_closure() = default;
60 
61  template<typename R>
62  constexpr typename return_category_type<R&&>::return_type
63  operator()(R&& r) const {
64  return (*this)(std::forward<R>(r), return_category_type<R&&>{});
65  }
66 };
67 
68 } // namespace detail
69 
70 namespace niebloid {
71 
74 
83 
85 
86 } // namespace niebloid
87 using namespace niebloid;
88 
89 namespace detail {
90 
92 struct all_t_impl {
93  using type = decltype(views::all(std::declval<R>()));
94 };
95 
96 template<typename R>
97 struct all_t_impl<R, false> {};
98 
99 } // namespace detail
100 
101 
104 
106 template<typename R>
108 
110 
111 } // namespace views
112 } // namespace ranges
113 } // namespace vccc
114 
115 #endif // VCCC_RANGES_VIEWS_ALL_HPP
constexpr return_category_type< R && >::return_type operator()(R &&r) const
Definition: all.hpp:63
typename detail::all_t_impl< R >::type all_t
Calculates the suitable view type of a viewable_range type.
Definition: all.hpp:107
constexpr VCCC_INLINE_OR_STATIC detail::all_adaptor_closure all
a view that includes all elements of a range
Definition: all.hpp:82
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: conjunction.hpp:22
helper base class template for defining a range adaptor closure object
Definition: range_adaptor_closure.hpp:96
specifies that a type is a range, that is, it provides a begin iterator and an end sentinel
Definition: range.hpp:53
specifies that a range is a view, that is, it has constant time copy/move/assignment
Definition: view.hpp:31
decltype(views::all(std::declval< R >())) type
Definition: all.hpp:93