Skip to content

Commit 42fc455

Browse files
committed
has_member static_const
1 parent 7ed6b71 commit 42fc455

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

include/nbl/builtin/hlsl/member_test_macros.hlsl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ namespace hlsl
1616
namespace impl
1717
{
1818

19+
template<class T, bool C>
20+
struct is_const_helper : bool_constant<C>
21+
{
22+
NBL_CONSTEXPR_STATIC_INLINE bool is_constant = is_const<T>::value;
23+
};
24+
1925
enum e_member_presence
2026
{
2127
absent = 0,
22-
non_static,
23-
as_static
28+
non_static = 1,
29+
as_static = 2,
30+
static_constexpr = 3,
2431
};
2532

2633
template<class T>
@@ -34,27 +41,23 @@ typedef impl::e_member_presence e_member_presence;
3441
}
3542

3643

37-
#define NBL_GENERATE_MEMBER_TESTER(mem) \
44+
#define NBL_GENERATE_MEMBER_TESTER(a) \
3845
namespace nbl \
3946
{ \
4047
namespace hlsl \
4148
{ \
42-
namespace impl \
43-
{ \
49+
namespace impl { \
50+
template<class T, class=void> \
51+
struct is_static_member_##a: false_type {NBL_CONSTEXPR_STATIC_INLINE bool is_constant = false; }; \
52+
template<class T> \
53+
struct is_static_member_##a<T,typename enable_if<!is_same<decltype(T::a),void>::value,void>::type>: is_const_helper<decltype(T::a), true> {}; \
4454
template<class T, class=void> \
45-
struct is_static_member_##mem: false_type {}; \
55+
struct is_member_##a: false_type {NBL_CONSTEXPR_STATIC_INLINE bool is_constant = false;}; \
4656
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{}; \
57+
struct is_member_##a<T,typename enable_if<!is_same<decltype(declval<T>().a),void>::value,void>::type> : is_const_helper<decltype(declval<T>().a), true>{}; \
5258
} \
5359
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-
}; \
60+
struct has_member_##a { NBL_CONSTEXPR_STATIC_INLINE e_member_presence value = (e_member_presence)(impl::is_member_##a<T>::value + impl::is_static_member_##a<T>::value + impl::is_static_member_##a<T>::is_constant); }; \
5861
} \
5962
}
6063

0 commit comments

Comments
 (0)