is_nullary.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*=============================================================================
  2. Copyright (c) 2005-2010 Joel de Guzman
  3. Copyright (c) 2010 Eric Niebler
  4. Copyright (c) 2010 Thomas Heller
  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_CORE_IS_NULLARY_HPP
  9. #define BOOST_PHOENIX_CORE_IS_NULLARY_HPP
  10. #include <boost/phoenix/core/limits.hpp>
  11. #include <boost/phoenix/core/environment.hpp>
  12. #include <boost/phoenix/core/is_actor.hpp>
  13. #include <boost/phoenix/core/meta_grammar.hpp>
  14. #include <boost/phoenix/core/terminal_fwd.hpp>
  15. #include <boost/phoenix/support/vector.hpp>
  16. #include <boost/proto/transform/fold.hpp>
  17. #include <boost/proto/transform/lazy.hpp>
  18. namespace boost { namespace phoenix
  19. {
  20. namespace result_of
  21. {
  22. template <typename Expr, typename Enable = void>
  23. struct is_nullary;
  24. }
  25. struct is_nullary
  26. {
  27. template <typename Rule, typename Dummy = void>
  28. struct when
  29. : proto::fold<
  30. proto::_
  31. , mpl::true_()
  32. , mpl::and_<
  33. proto::_state
  34. , proto::call<evaluator(proto::_, _context)>
  35. >()
  36. >
  37. {};
  38. };
  39. template <typename Dummy>
  40. struct is_nullary::when<rule::argument, Dummy>
  41. {
  42. BOOST_PROTO_TRANSFORM(is_nullary::when<rule::argument>)
  43. template <typename Expr, typename State, typename Data>
  44. struct impl
  45. {
  46. typedef mpl::false_ result_type;
  47. };
  48. };
  49. template <
  50. typename Trait
  51. , typename Expr
  52. , typename State
  53. , typename Data
  54. , bool IsTransform = proto::is_transform<Trait>::value
  55. >
  56. struct is_nullary_custom_terminal_impl
  57. {
  58. typedef typename Trait::type result_type;
  59. };
  60. template <typename Transform, typename Expr, typename State, typename Data>
  61. struct is_nullary_custom_terminal_impl<Transform, Expr, State, Data, true>
  62. {
  63. typedef
  64. typename Transform::template impl<
  65. Expr
  66. , State
  67. , Data
  68. >::result_type
  69. result_type;
  70. };
  71. template <typename Dummy>
  72. struct is_nullary::when<rule::custom_terminal, Dummy>
  73. {
  74. BOOST_PROTO_TRANSFORM(is_nullary::when<rule::custom_terminal>)
  75. template <typename Expr, typename State, typename Data>
  76. struct impl
  77. : is_nullary_custom_terminal_impl<
  78. result_of::is_nullary<
  79. custom_terminal<
  80. typename proto::detail::uncvref<
  81. typename proto::result_of::value<Expr>::type
  82. >::type
  83. >
  84. >
  85. , typename proto::result_of::value<Expr>::type
  86. , State
  87. , Data
  88. >
  89. {};
  90. };
  91. template <typename Dummy>
  92. struct is_nullary::when<rule::terminal, Dummy>
  93. {
  94. BOOST_PROTO_TRANSFORM(is_nullary::when<rule::terminal>)
  95. template <typename Expr, typename State, typename Data>
  96. struct impl
  97. {
  98. typedef mpl::true_ result_type;
  99. };
  100. };
  101. namespace result_of
  102. {
  103. template <typename Expr, typename Enable>
  104. struct is_nullary
  105. : boost::phoenix::evaluator::impl<
  106. Expr const &
  107. , vector2<
  108. mpl::true_
  109. , boost::phoenix::is_nullary
  110. >
  111. , proto::empty_env
  112. >::result_type
  113. {};
  114. template <typename T>
  115. struct is_nullary<T & >
  116. : is_nullary<T>
  117. {};
  118. template <typename T>
  119. struct is_nullary<T const & >
  120. : is_nullary<T>
  121. {};
  122. template <typename T>
  123. struct is_nullary<T const >
  124. : is_nullary<T>
  125. {};
  126. template <typename T>
  127. struct is_nullary<custom_terminal<T> >
  128. : mpl::true_
  129. {};
  130. template <typename T>
  131. struct is_nullary<custom_terminal<actor<T> > >
  132. : evaluator
  133. {};
  134. template <typename T>
  135. struct is_nullary<custom_terminal<boost::reference_wrapper<actor<T> > > >
  136. {
  137. BOOST_PROTO_TRANSFORM(is_nullary<custom_terminal<boost::reference_wrapper<actor<T> > > >)
  138. template <typename Expr, typename State, typename Data>
  139. struct impl
  140. {
  141. typedef typename evaluator::template impl<actor<T>, State, Data>::result_type result_type;
  142. };
  143. };
  144. template <typename T>
  145. struct is_nullary<custom_terminal<boost::reference_wrapper<actor<T> const> > >
  146. {
  147. BOOST_PROTO_TRANSFORM(is_nullary<custom_terminal<boost::reference_wrapper<actor<T> const> > >)
  148. template <typename Expr, typename State, typename Data>
  149. struct impl
  150. {
  151. typedef typename evaluator::template impl<actor<T> const, State, Data>::result_type result_type;
  152. };
  153. };
  154. }
  155. }}
  156. #endif