const_cast.hpp 2.0 KB

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