1
+ // Copyright (C) 2023 - DevSH Graphics Programming Sp. z O.O.
2
+ // This file is part of the "Nabla Engine".
3
+ // For conditions of distribution and use, see copyright notice in nabla.h
4
+
5
+ #ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_CONCEPT_INCLUDED_
6
+ #define _NBL_BUILTIN_HLSL_CPP_COMPAT_CONCEPT_INCLUDED_
7
+
8
+ #include <nbl/builtin/hlsl/cpp_compat/vector .hlsl>
9
+ #include <nbl/builtin/hlsl/cpp_compat/matrix .hlsl>
10
+ #include <nbl/builtin/hlsl/type_traits.hlsl>
11
+
12
+
13
+ #if (__cplusplus >= 202002L && __cpp_concepts)
14
+
15
+ #define NBL_CONCEPT_TYPE_PARAMS (...) template <__VA_ARGS__>
16
+ #define NBL_CONCEPT_SIGNATURE (NAME, ...) concept NAME = requires (__VA_ARGS__)
17
+ #define NBL_CONCEPT_BODY (...) { __VA_ARGS__ };
18
+ #define NBL_CONCEPT_ASSIGN (NAME, ...) concept NAME = __VA_ARGS__;
19
+ #define NBL_REQUIRES (...) requires __VA_ARGS__
20
+
21
+ #include <concepts>
22
+
23
+ namespace nbl
24
+ {
25
+ namespace hlsl
26
+ {
27
+ namespace concepts
28
+ {
29
+
30
+ // Alias some of the std concepts in nbl. As this is C++20 only, we don't need to use
31
+ // the macros here.
32
+ template <typename T, typename U>
33
+ concept same_as = std::same_as<T, U>;
34
+
35
+ template <typename D, typename B>
36
+ concept derived_from = std::derived_from<D, B>;
37
+
38
+ template <typename F, typename T>
39
+ concept convertible_to = std::convertible_to<F, T>;
40
+
41
+ template <typename T, typename F>
42
+ concept assignable_from = std::assignable_from<T, F>;
43
+
44
+ template <typename T, typename U>
45
+ concept common_with = std::common_with<T, U>;
46
+
47
+ template <typename T>
48
+ concept integral = std::integral<T>;
49
+
50
+ template <typename T>
51
+ concept signed_integral = std::signed_integral<T>;
52
+
53
+ template <typename T>
54
+ concept unsigned_integral = std::unsigned_integral<T>;
55
+
56
+ template <typename T>
57
+ concept floating_point = std::floating_point<T>;
58
+
59
+
60
+ // Some other useful concepts.
61
+
62
+ template<typename T, typename... Ts>
63
+ concept any_of = (same_as<T, Ts> || ...);
64
+
65
+ template <typename T>
66
+ concept scalar = floating_point<T> || integral<T>;
67
+
68
+ template <typename T>
69
+ concept vectorial = is_vector<T>::value;
70
+
71
+ template <typename T>
72
+ concept matricial = is_matrix<T>::value;
73
+
74
+ }
75
+ }
76
+ }
77
+
78
+ #else
79
+
80
+ // No C++20 support. Do nothing.
81
+ #define NBL_CONCEPT_TYPE_PARAMS (...)
82
+ #define NBL_CONCEPT_SIGNATURE (NAME, ...)
83
+ #define NBL_CONCEPT_BODY (...)
84
+ #define NBL_REQUIRES (...)
85
+
86
+ #endif
87
+
88
+ #endif
0 commit comments