All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
43 #include <blaze/util/FalseType.h>
44 #include <blaze/util/mpl/If.h>
45 #include <blaze/util/SelectType.h>
46 #include <blaze/util/TrueType.h>
48 
49 
50 
51 
52 //=================================================================================================
53 //
54 // MACRO DEFINITIONS
55 //
56 //=================================================================================================
57 
58 //*************************************************************************************************
100 #define BLAZE_CREATE_HAS_DATA_OR_FUNCTION_MEMBER_TYPE_TRAIT( TYPE_TRAIT_NAME, MEMBER_NAME ) \
101  \
102 template < typename TYPE1230 > \
103 class TYPE_TRAIT_NAME##HELPER \
104 { \
105  private: \
106  typedef char YES[1]; \
107  typedef char NO [2]; \
108  \
109  struct BASE {}; \
110  \
111  template< typename U, U > struct CHECK; \
112  \
113  struct FALLBACK { int MEMBER_NAME; }; \
114  \
115  struct DERIVED \
116  : blaze::If< blaze::IsBuiltin<TYPE1230>, BASE, TYPE1230 >::Type \
117  , FALLBACK \
118  {}; \
119  \
120  template < typename U > \
121  static NO& TEST( CHECK<int FALLBACK::*, &U::MEMBER_NAME>* ); \
122  \
123  template < typename U > \
124  static YES& TEST( ... ); \
125  \
126  public: \
127  enum { value = sizeof( TEST<DERIVED>( NULL ) ) == sizeof( YES ) }; \
128  typedef typename blaze::SelectType<value,blaze::TrueType,blaze::FalseType>::Type Type; \
129 }; \
130  \
131 template< typename TYPE1230 > \
132 struct TYPE_TRAIT_NAME : public TYPE_TRAIT_NAME##HELPER<TYPE1230>::Type \
133 { \
134  enum { value = TYPE_TRAIT_NAME##HELPER<TYPE1230>::value }; \
135  typedef typename TYPE_TRAIT_NAME##HELPER<TYPE1230>::Type Type; \
136 };
137 //*************************************************************************************************
138 
139 
140 //*************************************************************************************************
187 #define BLAZE_CREATE_HAS_TYPE_MEMBER_TYPE_TRAIT( TYPE_TRAIT_NAME, MEMBER_NAME ) \
188  \
189 template < typename TYPE1231 > \
190 struct TYPE_TRAIT_NAME##HELPER \
191 { \
192  private: \
193  typedef char YES[1]; \
194  typedef char NO [2]; \
195  \
196  struct BASE {}; \
197  \
198  struct FALLBACK { struct MEMBER_NAME { }; }; \
199  \
200  struct DERIVED \
201  : blaze::If< blaze::IsBuiltin<TYPE1231>, BASE, TYPE1231 >::Type \
202  , FALLBACK \
203  {}; \
204  \
205  template < class U > \
206  static NO& TEST( typename U::MEMBER_NAME* ); \
207  \
208  template < typename U > \
209  static YES& TEST( U* ); \
210  \
211  public: \
212  enum { value = sizeof( TEST<DERIVED>( NULL ) ) == sizeof( YES ) }; \
213  typedef typename blaze::SelectType<value,blaze::TrueType,blaze::FalseType>::Type Type; \
214 }; \
215  \
216 template< typename TYPE1231 > \
217 struct TYPE_TRAIT_NAME : public TYPE_TRAIT_NAME##HELPER<TYPE1231>::Type \
218 { \
219  enum { value = TYPE_TRAIT_NAME##HELPER<TYPE1231>::value }; \
220  typedef typename TYPE_TRAIT_NAME##HELPER<TYPE1231>::Type Type; \
221 };
222 //*************************************************************************************************
223 
224 
225 //*************************************************************************************************
272 #define BLAZE_CREATE_HAS_MEMBER_TYPE_TRAIT( TYPE_TRAIT_NAME, MEMBER_NAME ) \
273  \
274 template< typename Type1232 > \
275 struct TYPE_TRAIT_NAME##HELPER \
276 { \
277  private: \
278  BLAZE_CREATE_HAS_DATA_OR_FUNCTION_MEMBER_TYPE_TRAIT( LOCAL_TYPE_TRAIT_1, MEMBER_NAME ); \
279  BLAZE_CREATE_HAS_TYPE_MEMBER_TYPE_TRAIT( LOCAL_TYPE_TRAIT_2, MEMBER_NAME ); \
280  \
281  public: \
282  enum { value = LOCAL_TYPE_TRAIT_1<Type1232>::value || LOCAL_TYPE_TRAIT_2<Type1232>::value }; \
283  typedef typename blaze::SelectType<value,blaze::TrueType,blaze::FalseType>::Type Type; \
284 }; \
285  \
286 template< typename Type1232 > \
287 struct TYPE_TRAIT_NAME : public TYPE_TRAIT_NAME##HELPER<Type1232>::Type \
288 { \
289  public: \
290  enum { value = TYPE_TRAIT_NAME##HELPER<Type1232>::value }; \
291  typedef typename TYPE_TRAIT_NAME##HELPER<Type1232>::Type Type; \
292 };
293 //*************************************************************************************************
294 
295 #endif
Header file for the FalseType type/value trait base class.
Header file for the If class template.
Header file for the SelectType class template.
Header file for the IsBuiltin type trait.
Header file for the TrueType type/value trait base class.