fix doc example typo
[boost.git] / boost / detail / indirect_traits.hpp
blobf9c0cd6a04c5baf1044d5f13631500de630347b1
1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef INDIRECT_TRAITS_DWA2002131_HPP
6 # define INDIRECT_TRAITS_DWA2002131_HPP
7 # include <boost/type_traits/is_function.hpp>
8 # include <boost/type_traits/is_reference.hpp>
9 # include <boost/type_traits/is_pointer.hpp>
10 # include <boost/type_traits/is_class.hpp>
11 # include <boost/type_traits/is_const.hpp>
12 # include <boost/type_traits/is_volatile.hpp>
13 # include <boost/type_traits/is_member_function_pointer.hpp>
14 # include <boost/type_traits/is_member_pointer.hpp>
15 # include <boost/type_traits/remove_cv.hpp>
16 # include <boost/type_traits/remove_reference.hpp>
17 # include <boost/type_traits/remove_pointer.hpp>
19 # include <boost/type_traits/detail/ice_and.hpp>
20 # include <boost/detail/workaround.hpp>
22 # include <boost/mpl/eval_if.hpp>
23 # include <boost/mpl/if.hpp>
24 # include <boost/mpl/bool.hpp>
25 # include <boost/mpl/and.hpp>
26 # include <boost/mpl/not.hpp>
27 # include <boost/mpl/aux_/lambda_support.hpp>
29 # ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
30 # include <boost/detail/is_function_ref_tester.hpp>
31 # endif
33 namespace boost { namespace detail {
35 namespace indirect_traits {
37 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
38 template <class T>
39 struct is_reference_to_const : mpl::false_
43 template <class T>
44 struct is_reference_to_const<T const&> : mpl::true_
48 # if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
49 template<class T>
50 struct is_reference_to_const<T const volatile&> : mpl::true_
53 # endif
55 template <class T>
56 struct is_reference_to_function : mpl::false_
60 template <class T>
61 struct is_reference_to_function<T&> : is_function<T>
65 template <class T>
66 struct is_pointer_to_function : mpl::false_
70 // There's no such thing as a pointer-to-cv-function, so we don't need
71 // specializations for those
72 template <class T>
73 struct is_pointer_to_function<T*> : is_function<T>
77 template <class T>
78 struct is_reference_to_member_function_pointer_impl : mpl::false_
82 template <class T>
83 struct is_reference_to_member_function_pointer_impl<T&>
84 : is_member_function_pointer<typename remove_cv<T>::type>
89 template <class T>
90 struct is_reference_to_member_function_pointer
91 : is_reference_to_member_function_pointer_impl<T>
93 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
96 template <class T>
97 struct is_reference_to_function_pointer_aux
98 : mpl::and_<
99 is_reference<T>
100 , is_pointer_to_function<
101 typename remove_cv<
102 typename remove_reference<T>::type
103 >::type
107 // There's no such thing as a pointer-to-cv-function, so we don't need specializations for those
110 template <class T>
111 struct is_reference_to_function_pointer
112 : mpl::if_<
113 is_reference_to_function<T>
114 , mpl::false_
115 , is_reference_to_function_pointer_aux<T>
116 >::type
120 template <class T>
121 struct is_reference_to_non_const
122 : mpl::and_<
123 is_reference<T>
124 , mpl::not_<
125 is_reference_to_const<T>
131 template <class T>
132 struct is_reference_to_volatile : mpl::false_
136 template <class T>
137 struct is_reference_to_volatile<T volatile&> : mpl::true_
141 # if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
142 template <class T>
143 struct is_reference_to_volatile<T const volatile&> : mpl::true_
146 # endif
149 template <class T>
150 struct is_reference_to_pointer : mpl::false_
154 template <class T>
155 struct is_reference_to_pointer<T*&> : mpl::true_
159 template <class T>
160 struct is_reference_to_pointer<T* const&> : mpl::true_
164 template <class T>
165 struct is_reference_to_pointer<T* volatile&> : mpl::true_
169 template <class T>
170 struct is_reference_to_pointer<T* const volatile&> : mpl::true_
174 template <class T>
175 struct is_reference_to_class
176 : mpl::and_<
177 is_reference<T>
178 , is_class<
179 typename remove_cv<
180 typename remove_reference<T>::type
181 >::type
185 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
188 template <class T>
189 struct is_pointer_to_class
190 : mpl::and_<
191 is_pointer<T>
192 , is_class<
193 typename remove_cv<
194 typename remove_pointer<T>::type
195 >::type
199 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_pointer_to_class,(T))
202 # else
204 using namespace boost::detail::is_function_ref_tester_;
206 typedef char (&inner_yes_type)[3];
207 typedef char (&inner_no_type)[2];
208 typedef char (&outer_no_type)[1];
210 template <typename V>
211 struct is_const_help
213 typedef typename mpl::if_<
214 is_const<V>
215 , inner_yes_type
216 , inner_no_type
217 >::type type;
220 template <typename V>
221 struct is_volatile_help
223 typedef typename mpl::if_<
224 is_volatile<V>
225 , inner_yes_type
226 , inner_no_type
227 >::type type;
230 template <typename V>
231 struct is_pointer_help
233 typedef typename mpl::if_<
234 is_pointer<V>
235 , inner_yes_type
236 , inner_no_type
237 >::type type;
240 template <typename V>
241 struct is_class_help
243 typedef typename mpl::if_<
244 is_class<V>
245 , inner_yes_type
246 , inner_no_type
247 >::type type;
250 template <class T>
251 struct is_reference_to_function_aux
253 static T t;
254 BOOST_STATIC_CONSTANT(
255 bool, value = sizeof(detail::is_function_ref_tester(t,0)) == sizeof(::boost::type_traits::yes_type));
256 typedef mpl::bool_<value> type;
259 template <class T>
260 struct is_reference_to_function
261 : mpl::if_<is_reference<T>, is_reference_to_function_aux<T>, mpl::bool_<false> >::type
265 template <class T>
266 struct is_pointer_to_function_aux
268 static T t;
269 BOOST_STATIC_CONSTANT(
270 bool, value
271 = sizeof(::boost::type_traits::is_function_ptr_tester(t)) == sizeof(::boost::type_traits::yes_type));
272 typedef mpl::bool_<value> type;
275 template <class T>
276 struct is_pointer_to_function
277 : mpl::if_<is_pointer<T>, is_pointer_to_function_aux<T>, mpl::bool_<false> >::type
279 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_pointer_to_function,(T))
282 struct false_helper1
284 template <class T>
285 struct apply : mpl::false_
290 template <typename V>
291 typename is_const_help<V>::type reference_to_const_helper(V&);
292 outer_no_type
293 reference_to_const_helper(...);
295 struct true_helper1
297 template <class T>
298 struct apply
300 static T t;
301 BOOST_STATIC_CONSTANT(
302 bool, value
303 = sizeof(reference_to_const_helper(t)) == sizeof(inner_yes_type));
304 typedef mpl::bool_<value> type;
308 template <bool ref = true>
309 struct is_reference_to_const_helper1 : true_helper1
313 template <>
314 struct is_reference_to_const_helper1<false> : false_helper1
319 template <class T>
320 struct is_reference_to_const
321 : is_reference_to_const_helper1<is_reference<T>::value>::template apply<T>
326 template <bool ref = true>
327 struct is_reference_to_non_const_helper1
329 template <class T>
330 struct apply
332 static T t;
333 BOOST_STATIC_CONSTANT(
334 bool, value
335 = sizeof(reference_to_const_helper(t)) == sizeof(inner_no_type));
337 typedef mpl::bool_<value> type;
341 template <>
342 struct is_reference_to_non_const_helper1<false> : false_helper1
347 template <class T>
348 struct is_reference_to_non_const
349 : is_reference_to_non_const_helper1<is_reference<T>::value>::template apply<T>
351 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_non_const,(T))
355 template <typename V>
356 typename is_volatile_help<V>::type reference_to_volatile_helper(V&);
357 outer_no_type
358 reference_to_volatile_helper(...);
360 template <bool ref = true>
361 struct is_reference_to_volatile_helper1
363 template <class T>
364 struct apply
366 static T t;
367 BOOST_STATIC_CONSTANT(
368 bool, value
369 = sizeof(reference_to_volatile_helper(t)) == sizeof(inner_yes_type));
370 typedef mpl::bool_<value> type;
374 template <>
375 struct is_reference_to_volatile_helper1<false> : false_helper1
380 template <class T>
381 struct is_reference_to_volatile
382 : is_reference_to_volatile_helper1<is_reference<T>::value>::template apply<T>
386 template <typename V>
387 typename is_pointer_help<V>::type reference_to_pointer_helper(V&);
388 outer_no_type reference_to_pointer_helper(...);
390 template <class T>
391 struct reference_to_pointer_impl
393 static T t;
394 BOOST_STATIC_CONSTANT(
395 bool, value
396 = (sizeof((reference_to_pointer_helper)(t)) == sizeof(inner_yes_type))
399 typedef mpl::bool_<value> type;
402 template <class T>
403 struct is_reference_to_pointer
404 : mpl::eval_if<is_reference<T>, reference_to_pointer_impl<T>, mpl::false_>::type
406 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_pointer,(T))
409 template <class T>
410 struct is_reference_to_function_pointer
411 : mpl::eval_if<is_reference<T>, is_pointer_to_function_aux<T>, mpl::false_>::type
413 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T))
417 template <class T>
418 struct is_member_function_pointer_help
419 : mpl::if_<is_member_function_pointer<T>, inner_yes_type, inner_no_type>
422 template <typename V>
423 typename is_member_function_pointer_help<V>::type member_function_pointer_helper(V&);
424 outer_no_type member_function_pointer_helper(...);
426 template <class T>
427 struct is_pointer_to_member_function_aux
429 static T t;
430 BOOST_STATIC_CONSTANT(
431 bool, value
432 = sizeof((member_function_pointer_helper)(t)) == sizeof(inner_yes_type));
433 typedef mpl::bool_<value> type;
436 template <class T>
437 struct is_reference_to_member_function_pointer
438 : mpl::if_<
439 is_reference<T>
440 , is_pointer_to_member_function_aux<T>
441 , mpl::bool_<false>
442 >::type
444 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
447 template <typename V>
448 typename is_class_help<V>::type reference_to_class_helper(V const volatile&);
449 outer_no_type reference_to_class_helper(...);
451 template <class T>
452 struct is_reference_to_class
454 static T t;
455 BOOST_STATIC_CONSTANT(
456 bool, value
457 = (is_reference<T>::value
458 & (sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type)))
460 typedef mpl::bool_<value> type;
461 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
464 template <typename V>
465 typename is_class_help<V>::type pointer_to_class_helper(V const volatile*);
466 outer_no_type pointer_to_class_helper(...);
468 template <class T>
469 struct is_pointer_to_class
471 static T t;
472 BOOST_STATIC_CONSTANT(
473 bool, value
474 = (is_pointer<T>::value
475 && sizeof(pointer_to_class_helper(t)) == sizeof(inner_yes_type))
477 typedef mpl::bool_<value> type;
479 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
483 using namespace indirect_traits;
485 }} // namespace boost::python::detail
487 #endif // INDIRECT_TRAITS_DWA2002131_HPP