value.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_CORE_VALUE_HPP
  8. #define BOOST_PHOENIX_CORE_VALUE_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/phoenix/core/actor.hpp>
  11. #include <boost/phoenix/core/as_actor.hpp>
  12. #include <boost/phoenix/core/terminal.hpp>
  13. #include <boost/utility/result_of.hpp>
  14. namespace boost { namespace phoenix
  15. {
  16. ////////////////////////////////////////////////////////////////////////////
  17. //
  18. // values
  19. //
  20. // function for evaluating values, e.g. val(123)
  21. //
  22. ////////////////////////////////////////////////////////////////////////////
  23. namespace expression
  24. {
  25. template <typename T>
  26. struct value
  27. : expression::terminal<T>
  28. {};
  29. }
  30. template <typename T>
  31. typename expression::value<T>::type const
  32. inline val(T t)
  33. {
  34. return expression::value<T>::make(t);
  35. }
  36. // Call out actor for special handling
  37. template<typename Expr>
  38. struct is_custom_terminal<actor<Expr> >
  39. : mpl::true_
  40. {};
  41. // Special handling for actor
  42. template<typename Expr>
  43. struct custom_terminal<actor<Expr> >
  44. {
  45. template <typename Sig>
  46. struct result;
  47. template <typename This, typename Actor, typename Context>
  48. struct result<This(Actor, Context)>
  49. : boost::remove_const<
  50. typename boost::remove_reference<
  51. typename evaluator::impl<Actor, Context, proto::empty_env>::result_type
  52. >::type
  53. >
  54. {};
  55. template <typename Context>
  56. typename result<custom_terminal(actor<Expr> const &, Context &)>::type
  57. operator()(actor<Expr> const & expr, Context & ctx) const
  58. {
  59. return boost::phoenix::eval(expr, ctx);
  60. }
  61. };
  62. namespace meta
  63. {
  64. template<typename T>
  65. struct const_ref
  66. : add_reference<typename add_const<T>::type>
  67. {};
  68. template<typename T>
  69. struct argument_type
  70. : mpl::eval_if_c<
  71. is_function<typename remove_pointer<T>::type>::value
  72. , mpl::identity<T>
  73. , const_ref<T>
  74. >
  75. {
  76. typedef T type;
  77. };
  78. template <typename T>
  79. struct decay
  80. {
  81. typedef T type;
  82. };
  83. template <typename T, int N>
  84. struct decay<T[N]> : decay<T const *> {};
  85. }
  86. template <typename T>
  87. struct as_actor<T, mpl::false_>
  88. {
  89. typedef typename expression::value<typename meta::decay<T>::type >::type type;
  90. static type
  91. convert(typename meta::argument_type<typename meta::decay<T>::type>::type t)
  92. {
  93. return expression::value<typename meta::decay<T>::type >::make(t);
  94. }
  95. };
  96. }}
  97. #endif