Skip to content

Commit 7ed6b71

Browse files
committed
test staticness
1 parent 3ecfc8e commit 7ed6b71

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

include/nbl/builtin/hlsl/member_test_macros.hlsl

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ namespace hlsl
1616
namespace impl
1717
{
1818

19-
template<class T>
20-
struct valid_expression : true_type {};
21-
22-
template<> struct valid_expression<void> : false_type {};
19+
enum e_member_presence
20+
{
21+
absent = 0,
22+
non_static,
23+
as_static
24+
};
2325

2426
template<class T>
2527
T declval(){}
2628

2729
}
2830

31+
typedef impl::e_member_presence e_member_presence;
2932
}
3033

3134
}
@@ -36,10 +39,22 @@ namespace nbl \
3639
{ \
3740
namespace hlsl \
3841
{ \
39-
template<class T, class=bool_constant<true> > \
40-
struct has_member_##mem : false_type {}; \
41-
template<class T> \
42-
struct has_member_##mem<T,bool_constant<impl::valid_expression<__decltype(impl::declval<T>().mem)>::value> > : true_type {}; \
42+
namespace impl \
43+
{ \
44+
template<class T, class=void> \
45+
struct is_static_member_##mem: false_type {}; \
46+
template<class T> \
47+
struct is_static_member_##mem<T,typename enable_if<!is_same<decltype(T::mem),void>::value,void>::type>: true_type{}; \
48+
template<class T, class=void> \
49+
struct is_member_##mem: false_type {}; \
50+
template<class T> \
51+
struct is_member_##mem<T,typename enable_if<!is_same<decltype(impl::declval<T>().mem),void>::value,void>::type>: true_type{}; \
52+
} \
53+
template<class T> \
54+
struct has_member_##mem \
55+
{ \
56+
NBL_CONSTEXPR_STATIC_INLINE e_member_presence value = (e_member_presence)(impl::is_member_##mem<T>::value + impl::is_static_member_##mem<T>::value); \
57+
}; \
4358
} \
4459
}
4560

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/type_traits.hlsl")
261261
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/limits.hlsl")
262262
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/mpl.hlsl")
263263
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/macros.h")
264+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/member_test_macros.hlsl")
264265

265266
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/circle.hlsl")
266267
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/ellipse.hlsl")

0 commit comments

Comments
 (0)