ossrv_pub/boost_apis/boost/parameter/aux_/cast.hpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright Daniel Wallin 2006. Use, modification and distribution is
       
     2 // subject to the Boost Software License, Version 1.0. (See accompanying
       
     3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       
     4 
       
     5 #ifndef BOOST_PARAMETER_CAST_060902_HPP
       
     6 # define BOOST_PARAMETER_CAST_060902_HPP
       
     7 
       
     8 # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
       
     9   && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
       
    10 #  include <boost/type_traits/add_reference.hpp>
       
    11 #  include <boost/type_traits/remove_const.hpp>
       
    12 # endif
       
    13 
       
    14 namespace boost { namespace parameter { namespace aux {
       
    15 
       
    16 struct use_default_tag {};
       
    17 
       
    18 # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
       
    19   || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
       
    20 
       
    21 #  define BOOST_PARAMETER_FUNCTION_CAST(value, predicate) value
       
    22 
       
    23 # else
       
    24 
       
    25 // Handles possible implicit casts. Used by preprocessor.hpp to
       
    26 // normalize user input.
       
    27 //
       
    28 // cast<void*>::execute() is identity
       
    29 // cast<void*(X)>::execute() is identity
       
    30 // cast<void(X)>::execute() casts to X
       
    31 //
       
    32 // preprocessor.hpp uses this like this:
       
    33 //
       
    34 //   #define X(value, predicate)
       
    35 //      cast<void predicate>::execute(value)
       
    36 //
       
    37 //   X(something, *)
       
    38 //   X(something, *(predicate))
       
    39 //   X(something, (int))
       
    40 
       
    41 template <class T>
       
    42 struct cast;
       
    43 
       
    44 template <>
       
    45 struct cast<void*>
       
    46 {
       
    47     static use_default_tag execute(use_default_tag)
       
    48     {
       
    49         return use_default_tag();
       
    50     }
       
    51 
       
    52     static use_default_tag remove_const(use_default_tag)
       
    53     {
       
    54         return use_default_tag();
       
    55     }
       
    56 
       
    57     template <class U>
       
    58     static U& execute(U& value)
       
    59     {
       
    60         return value;
       
    61     }
       
    62 
       
    63     template <class U>
       
    64     static U& remove_const(U& x)
       
    65     {
       
    66         return x;
       
    67     }
       
    68 };
       
    69 
       
    70 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
       
    71 
       
    72 typedef void* voidstar;
       
    73 
       
    74 template <class T>
       
    75 struct cast<voidstar(T)>
       
    76   : cast<void*>
       
    77 {
       
    78 };
       
    79 
       
    80 #else
       
    81 
       
    82 template <class T>
       
    83 struct cast<void*(T)>
       
    84   : cast<void*>
       
    85 {
       
    86 };
       
    87 
       
    88 #endif
       
    89 
       
    90 template <class T>
       
    91 struct cast<void(T)>
       
    92 {
       
    93     typedef typename boost::add_reference<
       
    94         typename boost::remove_const<T>::type 
       
    95     >::type reference;
       
    96 
       
    97     static use_default_tag execute(use_default_tag)
       
    98     {
       
    99         return use_default_tag();
       
   100     }
       
   101 
       
   102     static use_default_tag remove_const(use_default_tag)
       
   103     {
       
   104         return use_default_tag();
       
   105     }
       
   106 
       
   107     static T execute(T value)
       
   108     {
       
   109         return value;
       
   110     }
       
   111 
       
   112     template <class U>
       
   113     static reference remove_const(U const& x)
       
   114     {
       
   115         return const_cast<reference>(x);
       
   116     }
       
   117 };
       
   118 
       
   119 #  define BOOST_PARAMETER_FUNCTION_CAST(value, predicate) \
       
   120     boost::parameter::aux::cast<void predicate>::remove_const( \
       
   121         boost::parameter::aux::cast<void predicate>::execute(value) \
       
   122     )
       
   123 
       
   124 # endif
       
   125 
       
   126 }}} // namespace boost::parameter::aux
       
   127 
       
   128 #endif // BOOST_PARAMETER_CAST_060902_HPP
       
   129