Skip to content

Commit 049c14f

Browse files
committed
GPU: provide the std type_traits subset used on Metal
MSL has no standard library, so the handful of traits the GPU code relies on are defined for __METAL__, as is already done for the other device compilers.
1 parent b122c5f commit 049c14f

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

GPU/Common/GPUCommonTypeTraits.h

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,122 @@
2121
#ifndef GPUCA_GPUCODE_COMPILEKERNELS
2222
#include <type_traits>
2323
#endif
24+
#elif defined(__METAL__)
25+
namespace std
26+
{
27+
template <bool B, class T, class F>
28+
struct conditional {
29+
typedef T type;
30+
};
31+
template <class T, class F>
32+
struct conditional<false, T, F> {
33+
typedef F type;
34+
};
35+
template <bool B, class T, class F>
36+
using contitional_t = typename conditional<B, T, F>::type;
37+
38+
template <class T, class U>
39+
struct is_same {
40+
enum { value = false };
41+
};
42+
template <class T>
43+
struct is_same<T, T> {
44+
enum { value = true };
45+
};
46+
template <class T, class U>
47+
constant static constexpr bool is_same_v = is_same<T, U>::value;
48+
49+
template <bool B, class T = void>
50+
struct enable_if {
51+
};
52+
template <class T>
53+
struct enable_if<true, T> {
54+
typedef T type;
55+
};
56+
57+
template <class T>
58+
struct remove_cv {
59+
typedef T type;
60+
};
61+
template <class T>
62+
struct remove_cv<const T> {
63+
typedef T type;
64+
};
65+
template <class T>
66+
struct remove_cv<volatile T> {
67+
typedef T type;
68+
};
69+
template <class T>
70+
struct remove_cv<const volatile T> {
71+
typedef T type;
72+
};
73+
template <class T>
74+
using remove_cv_t = typename remove_cv<T>::type;
75+
76+
template <class T>
77+
struct remove_const {
78+
typedef T type;
79+
};
80+
template <class T>
81+
struct remove_const<const T> {
82+
typedef T type;
83+
};
84+
template <class T>
85+
using remove_const_t = typename remove_const<T>::type;
86+
87+
template <class T>
88+
struct remove_volatile {
89+
typedef T type;
90+
};
91+
template <class T>
92+
struct remove_volatile<volatile T> {
93+
typedef T type;
94+
};
95+
template <class T>
96+
using remove_volatile_t = typename remove_volatile<T>::type;
97+
98+
template <class T>
99+
struct is_pointer_t {
100+
enum { value = false };
101+
};
102+
template <class T>
103+
struct is_pointer_t<device T*> {
104+
enum { value = true };
105+
};
106+
// template <class T>
107+
// struct is_pointer : is_pointer_t<typename std::remove_cv<T>::type> {
108+
// };
109+
110+
template <class T>
111+
struct remove_reference {
112+
typedef T type;
113+
};
114+
template <class T>
115+
struct remove_reference<device T&> {
116+
typedef T type;
117+
};
118+
template <class T>
119+
struct remove_reference<device T&&> {
120+
typedef T type;
121+
};
122+
template <class T>
123+
using remove_reference_t = typename remove_reference<T>::type;
124+
125+
template <class T>
126+
struct is_member_pointer_helper {
127+
enum { value = false };
128+
};
129+
template <class T, class U>
130+
struct is_member_pointer_helper<T U::*> {
131+
enum { value = true };
132+
};
133+
// template <class T>
134+
// struct is_member_pointer : is_member_pointer_helper<typename std::remove_cv<T>::type> {
135+
// };
136+
// template <class T>
137+
// static constexpr bool is_member_pointer_v = is_member_pointer<T>::value;
138+
139+
} // namespace std
24140
#else
25141
namespace std
26142
{

0 commit comments

Comments
 (0)