static_cast.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_STATIC_CAST_HPP
  8. #define BOOST_PHOENIX_OBJECT_STATIC_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)(static_cast_)
  17. , (proto::terminal<detail::target<proto::_> >)
  18. (meta_grammar)
  19. )
  20. namespace boost { namespace phoenix
  21. {
  22. struct static_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 static_cast<
  35. typename detail::result_of::target<Target>::type
  36. >(boost::phoenix::eval(u, ctx));
  37. }
  38. };
  39. template <typename Dummy>
  40. struct default_actions::when<rule::static_cast_, Dummy>
  41. : call<static_cast_eval, Dummy>
  42. {};
  43. template <typename T, typename U>
  44. inline
  45. typename expression::static_cast_<detail::target<T>, U>::type const
  46. static_cast_(U const& u)
  47. {
  48. return
  49. expression::
  50. static_cast_<detail::target<T>, U>::
  51. make(detail::target<T>(), u);
  52. }
  53. }}
  54. #endif