2
3
4
5
6
7
8
11#ifndef _GLSL_STRUCT_ARRAY_TRAITS_HPP_
12 #define _GLSL_STRUCT_ARRAY_TRAITS_HPP_
14 #include <glslstruct/config.hpp>
17_GLSL_STRUCT_ERROR(
"This is only available for c++17 and greater!");
20 #include <glslstruct/libs.hpp>
22namespace glslstruct::utils {
23 #pragma region ARRAY_TRAITS
26
27
28
29
31 struct array_traits {};
34
35
36
37
39 struct array_traits<std::vector<T> > {
51
52
53
54
55
56 template<
class T, size_t N>
57 struct array_traits<std::array<T, N> > {
72
73
74
75
76
77 template<
class T, size_t N>
78 struct array_traits<T[N]> {
93
94
95
96
97
98 template<
class T, size_t N>
99 struct array_traits<T (*)[N]> {
101 using value_type = T;
115
116
117
118
120 struct array_traits<std::span<T> > {
122 using value_type = T;
125 static _GLSL_STRUCT_CONSTEXPR17
const T* data(
const std::span<
const T> span) {
return span.data(); }
128 static _GLSL_STRUCT_CONSTEXPR17 size_t size(
const std::span<
const T> span) {
return span.size(); }
133 #pragma region ARRAY_CHECKS
135
136
137
138
141
142
143
144
148
149
150
152 concept array = requires (
const T& value) {
153 typename array_traits<T>::value_type;
154 { array_traits<T>::data(value) } -> std::same_as<
const typename array_traits<T>::value_type*>;
155 { array_traits<T>::size(value) } -> std::same_as<size_t>;
159
160
161
163 concept static_size_array = array<T> && requires {
164 { array_traits<T>::static_size } -> std::convertible_to<size_t>;
168 static _GLSL_STRUCT_CONSTEXPR17
bool is_array_v = array<T>;
171 static _GLSL_STRUCT_CONSTEXPR17
bool is_static_size_array_v = static_size_array<T>;
174
175
176
177 template<
class T,
class =
void>
178 struct is_array : std::false_type {};
181 struct is_array<T, std::void_t<
typename array_traits<T>::value_type,
182 std::enable_if_t<std::is_same_v<
decltype(array_traits<T>::data(std::declval<
const T&>())),
183 const typename array_traits<T>::value_type*> >,
184 std::enable_if_t<std::is_same_v<
decltype(array_traits<T>::size(std::declval<
const T&>())), size_t> > > >
191
192
193
194 template<
class T,
class =
void>
195 struct is_static_size_array : std::false_type {};
198 struct is_static_size_array<T, std::void_t<std::enable_if_t<is_array_v<T> >,
199 std::enable_if_t<std::is_convertible_v<
decltype(array_traits<T>::static_size), size_t> > > >
207 #pragma region ARRAY_TRAITS_VALUES
209
210
211
215 template<
class T, std::enable_if_t<is_array_v<T>,
bool> =
true>
220
221
222
224 template<static_size_array T>
226 template<
class T, std::enable_if_t<is_static_size_array_v<T>,
bool> =
true>
231
232
233
237 template<
class T, std::enable_if_t<is_array_v<T>,
bool> =
true>
240 return array_traits<T>::data(value);
244
245
246
250 template<
class T, std::enable_if_t<is_array_v<T>,
bool> =
true>
253 return array_traits<T>::size(value);
258 #pragma region IS_ARRAY_OF
261
262
263
264
265
266
267 template<
template<
class,
class...>
class Test,
class T,
bool IsArray =
false,
class... Args>
268 struct is_array_of : std::false_type {};
270 template<
template<
class,
class...>
class Test,
class T,
class... Args>
271 struct is_array_of<Test, T,
true, Args...> : Test<array_value_type_t<T>, Args...> {};
274
275
276
277 template<
template<
class,
class...>
class Test,
class T,
class... Args>
281
282
283
284
285
286
287
288 template<
template<
class,
class...>
class Test,
class T,
bool IsArray =
false,
class... Args>
289 struct is_static_size_array_of_impl : std::false_type {};
291 template<
template<
class,
class...>
class Test,
class T,
class... Args>
292 struct is_static_size_array_of_impl<Test, T,
true, Args...> : Test<array_value_type_t<T>, Args...> {};
295
296
297
298
299
300
301 template<
template<
class,
class...>
class Test,
class T,
class... Args>
302 struct is_static_size_array_of : is_static_size_array_of_impl<Test, T, is_array_v<T>, Args...> {};
305
306
307
308 template<
template<
class,
class...>
class Test,
class T,
class... Args>
#define _GLSL_STRUCT_TYPENAME17
Definition config.hpp:216
#define _GLSL_STRUCT_HAS_CXX20
check if compiler has c++ version greater or equal to c++20 and if user enabled c++20 features using ...
Definition config.hpp:142
#define _GLSL_STRUCT_HAS_CXX17
check if compiler has c++ version greater or equal to c++17
Definition config.hpp:130
#define _GLSL_STRUCT_CONSTEXPR17
constexpr for c++17 and higher
Definition config.hpp:196