OGLplus  (0.59.0) a C++ wrapper for rendering APIs

vec_mat_traits.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_VEC_MAT_TRAITS_HPP
10 #define EAGINE_VEC_MAT_TRAITS_HPP
11 
12 #include "nothing.hpp"
13 #include "span.hpp"
14 #include "type_identity.hpp"
15 #include <type_traits>
16 
17 namespace eagine {
18 
19 template <typename T>
20 struct is_known_vector_type : std::false_type {};
21 
22 template <typename T>
23 constexpr const bool is_known_vector_type_v = is_known_vector_type<T>::value;
24 
25 template <typename T, span_size_t N>
26 struct is_known_vector_type<T[N]> : std::is_scalar<T> {};
27 
28 template <typename T>
29 struct is_known_matrix_type : std::false_type {};
30 
31 template <typename T>
32 constexpr const bool is_known_matrix_type_v = is_known_matrix_type<T>::value;
33 
34 template <typename T, span_size_t C, span_size_t R>
35 struct is_known_matrix_type<T[C][R]> : std::is_scalar<T> {};
36 
37 template <typename T>
38 struct canonical_compound_type : nothing_t {};
39 
40 template <typename T>
41 using canonical_compound_type_t = typename canonical_compound_type<T>::type;
42 
43 template <typename C, typename CT>
44 struct has_canonical_type : std::is_same<canonical_compound_type_t<C>, CT> {};
45 
46 template <typename T, span_size_t N>
47 struct canonical_compound_type<T[N]> : type_identity<std::remove_cv_t<T[N]>> {};
48 
49 template <typename T, span_size_t C, span_size_t R>
50 struct canonical_compound_type<T[C][R]>
51  : type_identity<std::remove_cv_t<T[C][R]>> {};
52 
53 template <typename T>
54 struct compound_element_type : type_identity<std::remove_cv_t<T>> {};
55 
56 template <typename T, span_size_t N>
57 struct compound_element_type<T[N]> : type_identity<std::remove_cv_t<T>> {};
58 
59 template <typename T, span_size_t C, span_size_t R>
60 struct compound_element_type<T[C][R]> : type_identity<std::remove_cv_t<T>> {};
61 
62 template <typename T>
63 struct canonical_element_type
64  : compound_element_type<canonical_compound_type_t<T>> {};
65 
66 template <typename T>
67 using canonical_element_type_t = typename canonical_element_type<T>::type;
68 
69 template <typename C>
70 struct compound_view_maker;
71 
72 template <typename C>
73 static inline auto element_view(const C& c) noexcept {
74  return compound_view_maker<C>()(c);
75 }
76 
77 template <typename T, span_size_t N>
78 struct compound_view_maker<T[N]> {
79  auto operator()(T (&v)[N]) const noexcept -> span<T> {
80  return {static_cast<T*>(v), N};
81  }
82 };
83 
84 template <typename T, span_size_t N>
85 static inline auto element_view(T (&v)[N]) noexcept {
86  return compound_view_maker<T[N]>()(v);
87 }
88 
89 template <typename T, span_size_t C, span_size_t R>
90 struct compound_view_maker<T[C][R]> {
91  auto operator()(T (&v)[C][R]) const noexcept -> span<T> {
92  return {v[0], C * R};
93  }
94 };
95 
96 template <typename T, span_size_t C, span_size_t R>
97 static inline auto element_view(T (&m)[C][R]) noexcept {
98  return compound_view_maker<T[C][R]>()(m);
99 }
100 
101 template <typename C>
102 struct is_row_major : std::false_type {};
103 
104 } // namespace eagine
105 
106 #endif // EAGINE_VEC_MAT_TRAITS_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).