MADNESS  version 0.9
type_traits_bits.h
Go to the documentation of this file.
1 #ifndef MADNESS_TYPE_TRAITS_BITS_H
2 #define MADNESS_TYPE_TRAITS_BITS_H
3 
4 // Minimal functionality
5 
6 #include <cstddef>
7 #include <stdint.h>
10 
12 
13 namespace madness {
14  namespace tr1 {
15 
16  // for simplicity in the same order as
17  // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1424.htm
19 
20  template <typename T>
21  struct is_void : public false_type {} ;
22 
24  template <>
25  struct is_void <void> : public true_type {};
26 
28  template <class T>
29  class is_integral {
30  public:
31  static const bool value = false;
32  };
33 
35  template <class T>
36  struct is_floating_point : public false_type {};
37 
38  #define SET_TYPE_TRAIT(trait, T) template<> struct trait < T > : public true_type {}
39 
40  SET_TYPE_TRAIT(is_integral,unsigned char);
41  SET_TYPE_TRAIT(is_integral,unsigned short);
42  SET_TYPE_TRAIT(is_integral,unsigned int);
43  SET_TYPE_TRAIT(is_integral,unsigned long);
44  SET_TYPE_TRAIT(is_integral,unsigned long long);
45  SET_TYPE_TRAIT(is_integral,signed char);
46  SET_TYPE_TRAIT(is_integral,signed short);
47  SET_TYPE_TRAIT(is_integral,signed int);
48  SET_TYPE_TRAIT(is_integral,signed long);
49  SET_TYPE_TRAIT(is_integral,signed long long);
50  SET_TYPE_TRAIT(is_integral,bool);
51  SET_TYPE_TRAIT(is_integral,char);
52 
53  SET_TYPE_TRAIT(is_floating_point,float);
54  SET_TYPE_TRAIT(is_floating_point,double);
55  SET_TYPE_TRAIT(is_floating_point,long double);
56 
57  #undef SET_TYPE_TRAIT
58 
60  template <typename T>
61  struct is_array : public false_type {};
62 
64  template <typename T, std::size_t n>
65  struct is_array<T[n]> : public true_type {};
66 
68  template <typename T>
69  struct is_pointer : public false_type {};
70 
72  template <typename T>
73  struct is_pointer<T*> : public true_type {};
74 
76  template <typename T>
77  struct is_reference : public false_type {};
78 
80  template <typename T>
81  struct is_reference<T&> : public true_type {};
82 
84  template <typename T>
85  struct is_function {
87  };
88 
90  template <typename T>
93  };
94 
95  // Not using these
96  // is_member_object_pointer
97  // is_enum
98  // is_union
99  // is_class
100 
101  template <class T> struct is_arithmetic {
103  typedef bool value_type;
105  //operator type()const;
106  };
107 
109  template <class T>
110  struct is_fundamental {
111  typedef bool value_type;
113  //operator type()const;
114  };
115 
116  template <class T> struct is_object{
117  static const bool value =
120  || is_void<T>::value);
121  typedef bool value_type;
123  //operator type()const;
124  };
125 
126  // is_scalar
127 
128  template <class T> struct is_compound{
129  static const bool value = !is_fundamental<T>::value;
130  typedef bool value_type;
132  //operator type()const;
133  };
134 
135  // is_member_pointer
136 
138  template <typename T>
139  struct is_const : public false_type {} ;
140 
142  template <typename T>
143  struct is_const<const T> : public true_type {};
144 
145  // is_volatile
146  // is_pod
147  // is_empty
148  // is_polymorphic
149  // is_abstract;
150  // has_trivial_constructor;
151  // has_trivial_copy;
152  // has_trivial_assign;
153  // has_trivial_destructor;
154  // has_nothrow_constructor;
155  // has_nothrow_copy;
156  // has_nothrow_assign;
157  // is_signed;
158  // is_unsigned;
159 
161  template <typename A, typename B>
162  struct is_same : public false_type {};
163 
165  template <typename A>
166  struct is_same<A,A> : public true_type {};
167 
168  // is_convertible
169 
170  namespace detail {
171  typedef char (&yes)[1];
172  typedef char (&no)[2];
173 
174  template <typename B, typename D>
175  struct Host
176  {
177  operator B*() const;
178  operator D*();
179  };
180  }
181 
182  template <typename B, typename D>
183  struct is_base_of
184  {
185  template <typename T>
186  static detail::yes check(D*, T);
187  static detail::no check(B*, int);
188 
189  static const bool value = sizeof(check(detail::Host<B,D>(), int())) == sizeof(detail::yes);
190  };
191 
192  // is_convertible
193  // is_explicitly_convertible
194 
196  template <typename T>
197  struct remove_const {
198  typedef T type;
199  };
200 
202  template <typename T>
203  struct remove_const<const T> {
204  typedef T type;
205  };
206 
208  template <typename T>
210  typedef T type;
211  };
212 
214  template <typename T>
215  struct remove_volatile<volatile T> {
216  typedef T type;
217  };
218 
220  template <typename T>
221  struct remove_cv {
223  };
224 
226  template <typename T>
227  struct add_const {
228  typedef const T type;
229  };
230 
232  template <typename T>
233  struct add_const<const T> {
234  typedef const T type;
235  };
236 
237 
238  // template <class T> struct add_volatile;
239  // template <class T> struct add_cv;
240 
242  template <typename T>
244  typedef T type;
245  };
246 
248  template <typename T>
249  struct remove_reference<T&> {
250  typedef T type;
251  };
252 
253  // template <class T> struct add_lvalue_reference;
254  // template <class T> struct add_rvalue_reference;
255 
256  // // 20.6.6.3, sign modifications:
257  // template <class T> struct make_signed;
258  // template <class T> struct make_unsigned;
259 
260  // // 20.6.6.4, array modifications:
261  // template <class T> struct remove_extent;
262  // template <class T> struct remove_all_extents;
263  // // 20.6.6.5, pointer modifications:
264 
266  template <typename T>
267  struct remove_pointer {
268  typedef T type;
269  };
270 
272  template <typename T>
273  struct remove_pointer<T*> {
274  typedef T type;
275  };
276 
277  // template <class T> struct add_pointer;
278 
279  // // 20.6.7, other transformations:
280  // template <std::size_t Len, std::size_t Align> struct aligned_storage;
281  // template <std::size_t Len, class... Types> struct aligned_union;
282  // template <class T> struct decay;
283 
285 
289  template <bool B, class returnT>
290  struct enable_if {
291  typedef returnT type;
292  };
293 
295  template <class returnT>
296  struct enable_if<false, returnT> {};
297 
298  // template <bool, class T, class F> struct conditional;
299  // template <class... T> struct common_type;
300  }
301 }
302 
303 #endif
T type
Definition: type_traits_bits.h:250
T type
Definition: type_traits_bits.h:210
Tensor< double > B
Definition: tdse1d.cc:167
integral_constant< value_type, value > type
Definition: type_traits_bits.h:122
remove_const::type will be T
Definition: type_traits_bits.h:197
static const bool value
Definition: type_traits_bits.h:117
bool value_type
Definition: type_traits_bits.h:103
static const bool value
Definition: type_traits_bits.h:92
T type
Definition: type_traits_bits.h:204
returnT type
Definition: type_traits_bits.h:291
static detail::yes check(D *, T)
remove_volatile::type will be T
Definition: type_traits_bits.h:209
static const bool value
Definition: type_traits_bits.h:86
T type
Definition: type_traits_bits.h:244
T type
Definition: type_traits_bits.h:216
Function traits in the spirt of boost function traits.
Definition: function_traits_bits.h:10
char(& no)[2]
Definition: type_traits_bits.h:172
const T type
Definition: type_traits_bits.h:228
is_pointer::value will be true if T is a pointer type
Definition: type_traits_bits.h:69
is_reference::value will be true if T is a reference type
Definition: type_traits_bits.h:77
static const bool value
Definition: type_traits_bits.h:31
is_fundamental::value will be true if T is a fundamental type
Definition: type_traits_bits.h:110
is_same returns true if A and B are the same type
Definition: type_traits_bits.h:162
static const bool value
Definition: type_traits_bits.h:102
remove_reference<&T>::type will be T
Definition: type_traits_bits.h:243
is_const::value will be true if T is const
Definition: type_traits_bits.h:139
bool value_type
Definition: type_traits_bits.h:121
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
integral_constant< value_type, value > type
Definition: type_traits_bits.h:131
Member function traits in the spirt of boost function traits.
Definition: function_traits_bits.h:142
char(& yes)[1]
Definition: type_traits_bits.h:171
static const bool value
Definition: type_traits_bits.h:112
SET_TYPE_TRAIT(is_integral, unsigned char)
T type
Definition: type_traits_bits.h:268
remove_pointer::type will be T
Definition: type_traits_bits.h:267
remove_volatile< typename remove_const< T >::type >::type type
Definition: type_traits_bits.h:222
bool value_type
Definition: type_traits_bits.h:130
add_const::type will be const T
Definition: type_traits_bits.h:227
T type
Definition: type_traits_bits.h:198
Definition: type_traits_bits.h:128
std::enable_if is similar to boost::enable_if_c for conditionally instantiating templates based on ty...
Definition: type_traits_bits.h:290
static const bool value
Definition: type_traits_bits.h:189
integral_constant< value_type, value > type
Definition: type_traits_bits.h:104
is_floating_point::value will be true if T is a fundamental floating-point type ...
Definition: type_traits_bits.h:36
Definition: type_traits_bits.h:175
bool value_type
Definition: type_traits_bits.h:111
true if T is void
Definition: type_traits_bits.h:21
remove_cv::type or remove_cv::type will be T
Definition: type_traits_bits.h:221
Definition: integral_constant.h:7
static const bool value
Definition: type_traits_bits.h:129
is_function::value is true if T is a function pointer
Definition: type_traits_bits.h:85
Definition: type_traits_bits.h:101
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
is_member_function_pointer::value is true if T is a member function pointer
Definition: type_traits_bits.h:91
is_array::value will be true if T is an array type
Definition: type_traits_bits.h:61
Definition: type_traits_bits.h:183
T type
Definition: type_traits_bits.h:274
is_integral::value will be true if T is a fundamental integer type
Definition: type_traits_bits.h:29
Definition: type_traits_bits.h:116
const T type
Definition: type_traits_bits.h:234