2
3
4
5
6
7
8
11#ifndef _GLSL_STRUCT_IS_VECTOR_OF_HPP_
12 #define _GLSL_STRUCT_IS_VECTOR_OF_HPP_
17 #include <glslstruct/config.hpp>
20_GLSL_STRUCT_ERROR(
"This is only available for c++17 and greater!");
23 #include <glslstruct/libs.hpp>
25namespace glslstruct::utils {
26 #pragma region ARRAY_TRAITS
29
30
31
32
34 struct array_traits {};
37
38
39
40
42 struct array_traits<std::vector<T> > {
54
55
56
57
58
59 template<
class T, size_t N>
60 struct array_traits<std::array<T, N> > {
75
76
77
78
79
80 template<
class T, size_t N>
81 struct array_traits<T[N]> {
96
97
98
99
100
101 template<
class T, size_t N>
102 struct array_traits<T (*)[N]> {
104 using value_type = T;
118
119
120
121
123 struct array_traits<std::span<T> > {
125 using value_type = T;
128 static _GLSL_STRUCT_CONSTEXPR17
const T* data(
const std::span<
const T> span) {
return span.data(); }
131 static _GLSL_STRUCT_CONSTEXPR17 size_t size(
const std::span<
const T> span) {
return span.size(); }
136 #pragma region ARRAY_CHECKS
138
139
140
141
144
145
146
147
151
152
153
155 concept array = requires (
const T& value) {
156 typename array_traits<T>::value_type;
157 { array_traits<T>::data(value) } -> std::same_as<
const typename array_traits<T>::value_type*>;
158 { array_traits<T>::size(value) } -> std::same_as<size_t>;
162
163
164
166 concept static_size_array = array<T> && requires {
167 { array_traits<T>::static_size } -> std::convertible_to<size_t>;
171 static _GLSL_STRUCT_CONSTEXPR17
bool is_array_v = array<T>;
174 static _GLSL_STRUCT_CONSTEXPR17
bool is_static_size_array_v = static_size_array<T>;
177
178
179
180 template<
class T,
class =
void>
181 struct is_array : std::false_type {};
184 struct is_array<T, std::void_t<
typename array_traits<T>::value_type,
185 std::enable_if_t<std::is_same_v<
decltype(array_traits<T>::data(std::declval<
const T&>())),
186 const typename array_traits<T>::value_type*> >,
187 std::enable_if_t<std::is_same_v<
decltype(array_traits<T>::size(std::declval<
const T&>())), size_t> > > >
194
195
196
197 template<
class T,
class =
void>
198 struct is_static_size_array : std::false_type {};
201 struct is_static_size_array<T, std::void_t<std::enable_if_t<is_array_v<T> >,
202 std::enable_if_t<std::is_convertible_v<
decltype(array_traits<T>::static_size), size_t> > > >
210 #pragma region ARRAY_TRAITS_VALUES
212
213
214
218 template<
class T, std::enable_if_t<is_array_v<T>,
bool> =
true>
223
224
225
227 template<static_size_array T>
229 template<
class T, std::enable_if_t<is_static_size_array_v<T>,
bool> =
true>
234
235
236
240 template<
class T, std::enable_if_t<is_array_v<T>,
bool> =
true>
243 return array_traits<T>::data(value);
247
248
249
253 template<
class T, std::enable_if_t<is_array_v<T>,
bool> =
true>
256 return array_traits<T>::size(value);
261 #pragma region IS_ARRAY_OF
264
265
266
267
268
269
270 template<
template<
class,
class...>
class Test,
class T,
bool IsArray =
false,
class... Args>
271 struct is_array_of : std::false_type {};
273 template<
template<
class,
class...>
class Test,
class T,
class... Args>
274 struct is_array_of<Test, T,
true, Args...> : Test<array_value_type_t<T>, Args...> {};
277
278
279
280 template<
template<
class,
class...>
class Test,
class T,
class... Args>
284
285
286
287
288
289
290
291 template<
template<
class,
class...>
class Test,
class T,
bool IsArray =
false,
class... Args>
292 struct is_static_size_array_of_impl : std::false_type {};
294 template<
template<
class,
class...>
class Test,
class T,
class... Args>
295 struct is_static_size_array_of_impl<Test, T,
true, Args...> : Test<array_value_type_t<T>, Args...> {};
298
299
300
301
302
303
304 template<
template<
class,
class...>
class Test,
class T,
class... Args>
305 struct is_static_size_array_of : is_static_size_array_of_impl<Test, T, is_array_v<T>, Args...> {};
308
309
310
311 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