HasMember.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_TYPETRAITS_HASMEMBER_H_
36 #define _BLAZE_UTIL_TYPETRAITS_HASMEMBER_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/util/mpl/If.h>
46 
47 
48 
49 
50 //=================================================================================================
51 //
52 // MACRO DEFINITIONS
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
98 #define BLAZE_CREATE_HAS_DATA_OR_FUNCTION_MEMBER_TYPE_TRAIT( TYPE_TRAIT_NAME, MEMBER_NAME ) \
99  \
100 template < typename TYPE1230 > \
101 class TYPE_TRAIT_NAME##HELPER \
102 { \
103  private: \
104  using Yes = char[1]; \
105  using No = char[2]; \
106  \
107  struct Base {}; \
108  \
109  template< typename U, U > struct Check; \
110  \
111  struct Fallback { int MEMBER_NAME; }; \
112  \
113  struct Derived \
114  : blaze::If< blaze::IsBuiltin<TYPE1230>, Base, TYPE1230 >::Type \
115  , Fallback \
116  {}; \
117  \
118  template < typename U > \
119  static No& test( Check<int Fallback::*, &U::MEMBER_NAME>* ); \
120  \
121  template < typename U > \
122  static Yes& test( ... ); \
123  \
124  public: \
125  enum : bool { value = ( sizeof( test<Derived>( nullptr ) ) == sizeof( Yes ) ) }; \
126 }; \
127  \
128 template< typename TYPE1230 > \
129 struct TYPE_TRAIT_NAME \
130  : public blaze::BoolConstant< TYPE_TRAIT_NAME##HELPER<TYPE1230>::value > \
131 {};
132 //*************************************************************************************************
133 
134 
135 //*************************************************************************************************
182 #define BLAZE_CREATE_HAS_TYPE_MEMBER_TYPE_TRAIT( TYPE_TRAIT_NAME, MEMBER_NAME ) \
183  \
184 template < typename TYPE1231 > \
185 struct TYPE_TRAIT_NAME##HELPER \
186 { \
187  private: \
188  using Yes = char[1]; \
189  using No = char[2]; \
190  \
191  struct Base {}; \
192  \
193  struct Fallback { struct MEMBER_NAME { }; }; \
194  \
195  struct Derived \
196  : blaze::If< blaze::IsBuiltin<TYPE1231>, Base, TYPE1231 >::Type \
197  , Fallback \
198  {}; \
199  \
200  template < class U > \
201  static No& test( typename U::MEMBER_NAME* ); \
202  \
203  template < typename U > \
204  static Yes& test( U* ); \
205  \
206  public: \
207  enum : bool { value = ( sizeof( test<Derived>( nullptr ) ) == sizeof( Yes ) ) }; \
208 }; \
209  \
210 template< typename TYPE1231 > \
211 struct TYPE_TRAIT_NAME \
212  : public blaze::BoolConstant< TYPE_TRAIT_NAME##HELPER<TYPE1231>::value > \
213 {};
214 //*************************************************************************************************
215 
216 
217 //*************************************************************************************************
264 #define BLAZE_CREATE_HAS_MEMBER_TYPE_TRAIT( TYPE_TRAIT_NAME, MEMBER_NAME ) \
265  \
266 template< typename Type1232 > \
267 struct TYPE_TRAIT_NAME##HELPER \
268 { \
269  private: \
270  BLAZE_CREATE_HAS_DATA_OR_FUNCTION_MEMBER_TYPE_TRAIT( LOCAL_TYPE_TRAIT_1, MEMBER_NAME ); \
271  BLAZE_CREATE_HAS_TYPE_MEMBER_TYPE_TRAIT( LOCAL_TYPE_TRAIT_2, MEMBER_NAME ); \
272  \
273  public: \
274  static constexpr bool value = ( LOCAL_TYPE_TRAIT_1<Type1232>::value || \
275  LOCAL_TYPE_TRAIT_2<Type1232>::value ); \
276 }; \
277  \
278 template< typename Type1232 > \
279 struct TYPE_TRAIT_NAME \
280  : public blaze::BoolConstant< TYPE_TRAIT_NAME##HELPER<Type1232>::value > \
281 {};
282 //*************************************************************************************************
283 
284 #endif
Header file for the If class template.
Header file for the IsBuiltin type trait.
Header file for the IntegralConstant class template.