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)
5 #ifndef BOOST_PARAMETER_CAST_060902_HPP
6 # define BOOST_PARAMETER_CAST_060902_HPP
8 # include <boost/detail/workaround.hpp>
10 # if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
11 # include <boost/type_traits/add_reference.hpp>
12 # include <boost/type_traits/remove_const.hpp>
15 namespace boost { namespace parameter { namespace aux {
17 struct use_default_tag {};
19 # if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
21 # define BOOST_PARAMETER_FUNCTION_CAST(value, predicate) value
25 // Handles possible implicit casts. Used by preprocessor.hpp to
26 // normalize user input.
28 // cast<void*>::execute() is identity
29 // cast<void*(X)>::execute() is identity
30 // cast<void(X)>::execute() casts to X
32 // preprocessor.hpp uses this like this:
34 // #define X(value, predicate)
35 // cast<void predicate>::execute(value)
38 // X(something, *(predicate))
39 // X(something, (int))
41 template <class T, class Args>
45 struct cast<void*, Args>
47 static use_default_tag execute(use_default_tag)
49 return use_default_tag();
52 static use_default_tag remove_const(use_default_tag)
54 return use_default_tag();
58 static U& execute(U& value)
64 static U& remove_const(U& x)
70 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
72 typedef void* voidstar;
74 template <class T, class Args>
75 struct cast<voidstar(T), Args>
82 template <class T, class Args>
83 struct cast<void*(T), Args>
90 // This is a hack used in cast<> to turn the user supplied type,
91 // which may or may not be a placeholder expression into one, so
92 // that it will be properly evaluated by mpl::apply.
93 template <class T, class Dummy = mpl::_1>
94 struct as_placeholder_expr
99 template <class T, class Args>
100 struct cast<void(T), Args>
102 typedef typename mpl::apply2<
103 as_placeholder_expr<T>, Args, Args>::type type0;
105 typedef typename boost::add_reference<
106 typename boost::remove_const<type0>::type
109 static use_default_tag execute(use_default_tag)
111 return use_default_tag();
114 static use_default_tag remove_const(use_default_tag)
116 return use_default_tag();
119 static type0 execute(type0 value)
125 static reference remove_const(U const& x)
127 return const_cast<reference>(x);
131 # define BOOST_PARAMETER_FUNCTION_CAST(value, predicate, args) \
132 boost::parameter::aux::cast<void predicate, args>::remove_const( \
133 boost::parameter::aux::cast<void predicate, args>::execute(value) \
138 }}} // namespace boost::parameter::aux
140 #endif // BOOST_PARAMETER_CAST_060902_HPP