Skip to content

Commit 1497506

Browse files
committed
member tester macros
1 parent 92bd414 commit 1497506

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2022 - 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+
#ifndef _NBL_BUILTIN_HLSL_MEMBER_TEST_MACROS_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_MEMBER_TEST_MACROS_INCLUDED_
6+
7+
#include <nbl/builtin/hlsl/type_traits.hlsl>
8+
9+
#ifdef __HLSL_VERSION
10+
#define NBL_GENERATE_MEMBER_TESTER(mem) \
11+
namespace nbl\
12+
{\
13+
namespace hlsl\
14+
{\
15+
template<class T, class=bool_constant<true> > \
16+
struct has_member_##mem : false_type {}; \
17+
template<class T> \
18+
struct has_member_##mem<T,bool_constant<impl::valid_expression<decltype(impl::declval<T>().mem)>::value> > : true_type {}; \
19+
}\
20+
}
21+
22+
namespace nbl
23+
{
24+
namespace hlsl
25+
{
26+
27+
namespace impl
28+
{
29+
30+
template<class T>
31+
struct valid_expression : true_type {};
32+
33+
template<> struct valid_expression<void> : false_type {};
34+
35+
template<class T>
36+
T declval(){}
37+
38+
}
39+
40+
}
41+
42+
}
43+
44+
NBL_GENERATE_MEMBER_TESTER(x)
45+
NBL_GENERATE_MEMBER_TESTER(y)
46+
NBL_GENERATE_MEMBER_TESTER(z)
47+
NBL_GENERATE_MEMBER_TESTER(w)
48+
49+
#endif
50+
#endif

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ using integral_constant = std::integral_constant<T, val>;
487487
template<bool val>
488488
using bool_constant = std::bool_constant<val>;
489489

490+
using bool_constant = std::true_type;
491+
using false_type = std::false_type;
492+
490493
template <bool C, class T, class F>
491494
using conditional = std::conditional<C, T, F>;
492495

0 commit comments

Comments
 (0)