indirect_traits.hpp
Go to the documentation of this file.
00001 // Copyright David Abrahams 2002.
00002 // Distributed under the Boost Software License, Version 1.0. (See
00003 // accompanying file LICENSE_1_0.txt or copy at
00004 // http://www.boost.org/LICENSE_1_0.txt)
00005 #ifndef INDIRECT_TRAITS_DWA2002131_HPP
00006 # define INDIRECT_TRAITS_DWA2002131_HPP
00007 # include <boost/type_traits/is_function.hpp>
00008 # include <boost/type_traits/is_reference.hpp>
00009 # include <boost/type_traits/is_pointer.hpp>
00010 # include <boost/type_traits/is_class.hpp>
00011 # include <boost/type_traits/is_const.hpp>
00012 # include <boost/type_traits/is_volatile.hpp>
00013 # include <boost/type_traits/is_member_function_pointer.hpp>
00014 # include <boost/type_traits/is_member_pointer.hpp>
00015 # include <boost/type_traits/remove_cv.hpp>
00016 # include <boost/type_traits/remove_reference.hpp>
00017 # include <boost/type_traits/remove_pointer.hpp>
00018 
00019 # include <boost/type_traits/detail/ice_and.hpp>
00020 # include <boost/detail/workaround.hpp>
00021 
00022 # include <boost/mpl/eval_if.hpp>
00023 # include <boost/mpl/if.hpp>
00024 # include <boost/mpl/bool.hpp>
00025 # include <boost/mpl/and.hpp>
00026 # include <boost/mpl/not.hpp>
00027 # include <boost/mpl/aux_/lambda_support.hpp>
00028 
00029 #  ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00030 #   include <boost/detail/is_function_ref_tester.hpp>
00031 #  endif 
00032 
00033 namespace boost { namespace detail {
00034 
00035 namespace indirect_traits {
00036 
00037 #  ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00038 template <class T>
00039 struct is_reference_to_const : mpl::false_
00040 {
00041 };
00042 
00043 template <class T>
00044 struct is_reference_to_const<T const&> : mpl::true_
00045 {
00046 };
00047 
00048 #   if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
00049 template<class T>
00050 struct is_reference_to_const<T const volatile&> : mpl::true_
00051 {
00052 };
00053 #   endif 
00054 
00055 template <class T>
00056 struct is_reference_to_function : mpl::false_
00057 {
00058 };
00059 
00060 template <class T>
00061 struct is_reference_to_function<T&> : is_function<T>
00062 {
00063 };
00064 
00065 template <class T>
00066 struct is_pointer_to_function : mpl::false_
00067 {
00068 };
00069 
00070 // There's no such thing as a pointer-to-cv-function, so we don't need
00071 // specializations for those
00072 template <class T>
00073 struct is_pointer_to_function<T*> : is_function<T>
00074 {
00075 };
00076 
00077 template <class T>
00078 struct is_reference_to_member_function_pointer_impl : mpl::false_
00079 {
00080 };
00081 
00082 template <class T>
00083 struct is_reference_to_member_function_pointer_impl<T&>
00084     : is_member_function_pointer<typename remove_cv<T>::type>
00085 {
00086 };
00087 
00088 
00089 template <class T>
00090 struct is_reference_to_member_function_pointer
00091     : is_reference_to_member_function_pointer_impl<T>
00092 {
00093     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
00094 };
00095 
00096 template <class T>
00097 struct is_reference_to_function_pointer_aux
00098     : mpl::and_<
00099           is_reference<T>
00100         , is_pointer_to_function<
00101               typename remove_cv<
00102                   typename remove_reference<T>::type
00103               >::type
00104           >
00105       >
00106 {
00107     // There's no such thing as a pointer-to-cv-function, so we don't need specializations for those
00108 };
00109 
00110 template <class T>
00111 struct is_reference_to_function_pointer
00112     : mpl::if_<
00113           is_reference_to_function<T>
00114         , mpl::false_
00115         , is_reference_to_function_pointer_aux<T>
00116      >::type
00117 {
00118 };
00119 
00120 template <class T>
00121 struct is_reference_to_non_const
00122     : mpl::and_<
00123           is_reference<T>
00124         , mpl::not_<
00125              is_reference_to_const<T>
00126           >
00127       >
00128 {
00129 };
00130 
00131 template <class T>
00132 struct is_reference_to_volatile : mpl::false_
00133 {
00134 };
00135 
00136 template <class T>
00137 struct is_reference_to_volatile<T volatile&> : mpl::true_
00138 {
00139 };
00140 
00141 #   if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
00142 template <class T>
00143 struct is_reference_to_volatile<T const volatile&> : mpl::true_
00144 {
00145 };
00146 #   endif 
00147 
00148 
00149 template <class T>
00150 struct is_reference_to_pointer : mpl::false_
00151 {
00152 };
00153 
00154 template <class T>
00155 struct is_reference_to_pointer<T*&> : mpl::true_
00156 {
00157 };
00158 
00159 template <class T>
00160 struct is_reference_to_pointer<T* const&> : mpl::true_
00161 {
00162 };
00163 
00164 template <class T>
00165 struct is_reference_to_pointer<T* volatile&> : mpl::true_
00166 {
00167 };
00168 
00169 template <class T>
00170 struct is_reference_to_pointer<T* const volatile&> : mpl::true_
00171 {
00172 };
00173 
00174 template <class T>
00175 struct is_reference_to_class
00176     : mpl::and_<
00177           is_reference<T>
00178         , is_class<
00179               typename remove_cv<
00180                   typename remove_reference<T>::type
00181               >::type
00182           >
00183       >
00184 {
00185     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
00186 };
00187 
00188 template <class T>
00189 struct is_pointer_to_class
00190     : mpl::and_<
00191           is_pointer<T>
00192         , is_class<
00193               typename remove_cv<
00194                   typename remove_pointer<T>::type
00195               >::type
00196           >
00197       >
00198 {
00199     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_pointer_to_class,(T))
00200 };
00201 
00202 #  else
00203 
00204 using namespace boost::detail::is_function_ref_tester_;
00205 
00206 typedef char (&inner_yes_type)[3];
00207 typedef char (&inner_no_type)[2];
00208 typedef char (&outer_no_type)[1];
00209 
00210 template <typename V>
00211 struct is_const_help
00212 {
00213     typedef typename mpl::if_<
00214           is_const<V>
00215         , inner_yes_type
00216         , inner_no_type
00217         >::type type;
00218 };
00219 
00220 template <typename V>
00221 struct is_volatile_help
00222 {
00223     typedef typename mpl::if_<
00224           is_volatile<V>
00225         , inner_yes_type
00226         , inner_no_type
00227         >::type type;
00228 };
00229 
00230 template <typename V>
00231 struct is_pointer_help
00232 {
00233     typedef typename mpl::if_<
00234           is_pointer<V>
00235         , inner_yes_type
00236         , inner_no_type
00237         >::type type;
00238 };
00239 
00240 template <typename V>
00241 struct is_class_help
00242 {
00243     typedef typename mpl::if_<
00244           is_class<V>
00245         , inner_yes_type
00246         , inner_no_type
00247         >::type type;
00248 };
00249 
00250 template <class T>
00251 struct is_reference_to_function_aux
00252 {
00253     static T t;
00254     BOOST_STATIC_CONSTANT(
00255         bool, value = sizeof(detail::is_function_ref_tester(t,0)) == sizeof(::boost::type_traits::yes_type));
00256     typedef mpl::bool_<value> type;
00257  };
00258 
00259 template <class T>
00260 struct is_reference_to_function
00261     : mpl::if_<is_reference<T>, is_reference_to_function_aux<T>, mpl::bool_<false> >::type
00262 {
00263 };
00264 
00265 template <class T>
00266 struct is_pointer_to_function_aux
00267 {
00268     static T t;
00269     BOOST_STATIC_CONSTANT(
00270         bool, value
00271         = sizeof(::boost::type_traits::is_function_ptr_tester(t)) == sizeof(::boost::type_traits::yes_type));
00272     typedef mpl::bool_<value> type;
00273 };
00274 
00275 template <class T>
00276 struct is_pointer_to_function
00277     : mpl::if_<is_pointer<T>, is_pointer_to_function_aux<T>, mpl::bool_<false> >::type
00278 {
00279     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_pointer_to_function,(T))
00280 };
00281 
00282 struct false_helper1
00283 {
00284     template <class T>
00285     struct apply : mpl::false_
00286     {
00287     };
00288 };
00289 
00290 template <typename V>
00291 typename is_const_help<V>::type reference_to_const_helper(V&);    
00292 outer_no_type
00293 reference_to_const_helper(...);
00294 
00295 struct true_helper1
00296 {
00297     template <class T>
00298     struct apply
00299     {
00300         static T t;
00301         BOOST_STATIC_CONSTANT(
00302             bool, value
00303             = sizeof(reference_to_const_helper(t)) == sizeof(inner_yes_type));
00304         typedef mpl::bool_<value> type;
00305     };
00306 };
00307 
00308 template <bool ref = true>
00309 struct is_reference_to_const_helper1 : true_helper1
00310 {
00311 };
00312 
00313 template <>
00314 struct is_reference_to_const_helper1<false> : false_helper1
00315 {
00316 };
00317 
00318 
00319 template <class T>
00320 struct is_reference_to_const
00321     : is_reference_to_const_helper1<is_reference<T>::value>::template apply<T>
00322 {
00323 };
00324 
00325 
00326 template <bool ref = true>
00327 struct is_reference_to_non_const_helper1
00328 {
00329     template <class T>
00330     struct apply
00331     {
00332         static T t;
00333         BOOST_STATIC_CONSTANT(
00334             bool, value
00335             = sizeof(reference_to_const_helper(t)) == sizeof(inner_no_type));
00336         
00337         typedef mpl::bool_<value> type;
00338     };
00339 };
00340 
00341 template <>
00342 struct is_reference_to_non_const_helper1<false> : false_helper1
00343 {
00344 };
00345 
00346 
00347 template <class T>
00348 struct is_reference_to_non_const
00349     : is_reference_to_non_const_helper1<is_reference<T>::value>::template apply<T>
00350 {
00351     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_non_const,(T))
00352 };
00353 
00354 
00355 template <typename V>
00356 typename is_volatile_help<V>::type reference_to_volatile_helper(V&);    
00357 outer_no_type
00358 reference_to_volatile_helper(...);
00359 
00360 template <bool ref = true>
00361 struct is_reference_to_volatile_helper1
00362 {
00363     template <class T>
00364     struct apply
00365     {
00366         static T t;
00367         BOOST_STATIC_CONSTANT(
00368             bool, value
00369             = sizeof(reference_to_volatile_helper(t)) == sizeof(inner_yes_type));
00370         typedef mpl::bool_<value> type;
00371     };
00372 };
00373 
00374 template <>
00375 struct is_reference_to_volatile_helper1<false> : false_helper1
00376 {
00377 };
00378 
00379 
00380 template <class T>
00381 struct is_reference_to_volatile
00382     : is_reference_to_volatile_helper1<is_reference<T>::value>::template apply<T>
00383 {
00384 };
00385 
00386 template <typename V>
00387 typename is_pointer_help<V>::type reference_to_pointer_helper(V&);
00388 outer_no_type reference_to_pointer_helper(...);
00389 
00390 template <class T>
00391 struct reference_to_pointer_impl
00392 {
00393     static T t;
00394     BOOST_STATIC_CONSTANT(
00395         bool, value
00396         = (sizeof((reference_to_pointer_helper)(t)) == sizeof(inner_yes_type))
00397         );
00398     
00399     typedef mpl::bool_<value> type;
00400 };
00401     
00402 template <class T>
00403 struct is_reference_to_pointer
00404   : mpl::eval_if<is_reference<T>, reference_to_pointer_impl<T>, mpl::false_>::type
00405 {   
00406     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_pointer,(T))
00407 };
00408 
00409 template <class T>
00410 struct is_reference_to_function_pointer
00411   : mpl::eval_if<is_reference<T>, is_pointer_to_function_aux<T>, mpl::false_>::type
00412 {
00413     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T))
00414 };
00415 
00416 
00417 template <class T>
00418 struct is_member_function_pointer_help
00419     : mpl::if_<is_member_function_pointer<T>, inner_yes_type, inner_no_type>
00420 {};
00421 
00422 template <typename V>
00423 typename is_member_function_pointer_help<V>::type member_function_pointer_helper(V&);
00424 outer_no_type member_function_pointer_helper(...);
00425 
00426 template <class T>
00427 struct is_pointer_to_member_function_aux
00428 {
00429     static T t;
00430     BOOST_STATIC_CONSTANT(
00431         bool, value
00432         = sizeof((member_function_pointer_helper)(t)) == sizeof(inner_yes_type));
00433     typedef mpl::bool_<value> type;
00434 };
00435 
00436 template <class T>
00437 struct is_reference_to_member_function_pointer
00438     : mpl::if_<
00439         is_reference<T>
00440         , is_pointer_to_member_function_aux<T>
00441         , mpl::bool_<false>
00442      >::type
00443 {
00444     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
00445 };
00446 
00447 template <typename V>
00448 typename is_class_help<V>::type reference_to_class_helper(V const volatile&);
00449 outer_no_type reference_to_class_helper(...);
00450 
00451 template <class T>
00452 struct is_reference_to_class
00453 {
00454     static T t;
00455     BOOST_STATIC_CONSTANT(
00456         bool, value
00457         = (is_reference<T>::value
00458            & (sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type)))
00459         );
00460     typedef mpl::bool_<value> type;
00461     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
00462 };
00463 
00464 template <typename V>
00465 typename is_class_help<V>::type pointer_to_class_helper(V const volatile*);
00466 outer_no_type pointer_to_class_helper(...);
00467 
00468 template <class T>
00469 struct is_pointer_to_class
00470 {
00471     static T t;
00472     BOOST_STATIC_CONSTANT(
00473         bool, value
00474         = (is_pointer<T>::value
00475            && sizeof(pointer_to_class_helper(t)) == sizeof(inner_yes_type))
00476         );
00477     typedef mpl::bool_<value> type;
00478 };
00479 #  endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 
00480 
00481 }
00482 
00483 using namespace indirect_traits;
00484 
00485 }} // namespace boost::python::detail
00486 
00487 #endif // INDIRECT_TRAITS_DWA2002131_HPP


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29