VCCC  2024.05
VisualCamp Common C++ library
data.hpp
Go to the documentation of this file.
1 //
2 // Created by cosge on 2023-12-02.
3 //
4 
5 #ifndef VCCC_RANGES_DATA_HPP
6 #define VCCC_RANGES_DATA_HPP
7 
8 #include <type_traits>
9 
14 #include "vccc/__ranges/begin.hpp"
18 
19 namespace vccc {
20 namespace ranges {
21 namespace detail {
22 
23 using vccc::detail::return_category;
24 
25 template<typename P>
26 struct data_member_check_2 : std::false_type {
27  using category = return_category<0>;
28 };
29 template<typename P>
30 struct data_member_check_2<P*> : std::is_object<P> {
31  using category = return_category<1, P*>;
32 };
33 
34 template<typename T, typename = void>
35 struct data_member_check : std::false_type {
36  using category = return_category<0>;
37 };
38 template<typename T>
39 struct data_member_check<T, void_t<decltype( vccc_decay_copy(std::declval<T>().data()) )>>
40  : data_member_check_2<decltype( vccc_decay_copy(std::declval<T>().data()) )> {};
41 
42 
43 template<typename T, typename = void>
44 struct data_ranges_begin_check : std::false_type {
45  using category = return_category<0>;
46 };
47 template<typename T>
48 struct data_ranges_begin_check<T, void_t<decltype( ranges::begin(std::declval<T>()) )>>
49  : contiguous_iterator<decltype( ranges::begin(std::declval<T>()) )>
50 {
51  using category = return_category<2, decltype( vccc::to_address( ranges::begin(std::declval<T>()) ) )>;
52 };
53 
54 template<typename T>
55 struct data_category
56  : std::conditional_t<
57  data_member_check<T>::value, typename data_member_check<T>::category,
58  std::conditional_t<
59  data_ranges_begin_check<T>::value, typename data_ranges_begin_check<T>::category,
60  return_category<0>
61  >>{};
62 
63 struct data_niebloid {
64  template<typename T, std::enable_if_t<disjunction<
65  std::is_lvalue_reference<T&&>,
66  ranges::enable_borrowed_range<remove_cvref_t<T>>
67  >::value, int> = 0>
68  constexpr typename data_category<T&&>::return_type
69  operator()(T&& t) const {
70  return (*this)(std::forward<T>(t), data_category<T&&>{});
71  }
72 
73  private:
74  template<typename T, typename R>
75  constexpr R operator()(T&& t, return_category<1, R>) const {
76  return vccc_decay_copy(t.data());
77  }
78 
79  template<typename T, typename R>
80  constexpr R operator()(T&& t, return_category<2, R>) const {
82  }
83 };
84 
85 } // namespace detail
86 
87 namespace niebloid {
88 
91 
92 
103 VCCC_INLINE_OR_STATIC constexpr detail::data_niebloid data{};
104 
106 
107 } // namespace niebloid
108 using namespace niebloid;
109 
110 } // namespace ranges
111 } // namespace vccc
112 
113 #endif // VCCC_RANGES_DATA_HPP
#define vccc_decay_copy(x)
Definition: decay_copy.hpp:12
constexpr T * to_address(T *p) noexcept
Definition: to_address.hpp:37
constexpr VCCC_INLINE_OR_STATIC detail::data_niebloid data
obtains a pointer to the beginning of a contiguous range
Definition: data.hpp:103
constexpr VCCC_INLINE_OR_STATIC detail::begin_niebloid begin
returns an iterator to the beginning of a range
Definition: begin.hpp:116
void void_t
Definition: void_t.hpp:19
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
Definition: matrix.hpp:495
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35