1 /*============================================================================== 2 Copyright (c) 2001-2010 Joel de Guzman 3 Copyright (c) 2010 Thomas Heller 4 5 Distributed under the Boost Software License, Version 1.0. (See accompanying 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 ==============================================================================*/ 8 #ifndef BOOST_PHOENIX_OBJECT_CONST_CAST_HPP 9 #define BOOST_PHOENIX_OBJECT_CONST_CAST_HPP 10 11 #include <boost/phoenix/core/limits.hpp> 12 #include <boost/phoenix/core/call.hpp> 13 #include <boost/phoenix/core/expression.hpp> 14 #include <boost/phoenix/core/meta_grammar.hpp> 15 #include <boost/phoenix/object/detail/target.hpp> 16 #include <boost/proto/transform/lazy.hpp> 17 18 BOOST_PHOENIX_DEFINE_EXPRESSION( 19 (boost)(phoenix)(const_cast_) 20 , (proto::terminal<detail::target<proto::_> >) 21 (meta_grammar) 22 ) 23 24 namespace boost { namespace phoenix 25 { 26 struct const_cast_eval 27 { 28 template <typename Sig> 29 struct result; 30 31 template <typename This, typename Target, typename Source, typename Context> 32 struct result<This(Target, Source, Context)> 33 : detail::result_of::target<Target> 34 {}; 35 36 template <typename Target, typename Source, typename Context> 37 typename detail::result_of::target<Target>::type operator ()boost::phoenix::const_cast_eval38 operator()(Target, Source const& u, Context const& ctx) const 39 { 40 return 41 const_cast< 42 typename detail::result_of::target<Target>::type 43 >(boost::phoenix::eval(u, ctx)); 44 } 45 }; 46 47 template <typename Dummy> 48 struct default_actions::when<rule::const_cast_, Dummy> 49 : call<const_cast_eval, Dummy> 50 {}; 51 52 template <typename T, typename U> 53 inline 54 typename expression::const_cast_<detail::target<T>, U>::type const const_cast_(U const & u)55 const_cast_(U const& u) 56 { 57 return 58 expression:: 59 const_cast_<detail::target<T>, U>:: 60 make(detail::target<T>(), u); 61 } 62 }} 63 64 #endif 65