/Src/Dependencies/Boost/boost/proto/detail/as_expr.hpp

http://hadesmem.googlecode.com/ · C++ Header · 170 lines · 125 code · 25 blank · 20 comment · 4 complexity · 39dbd896040bcb1da12c68f00d987cc3 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////
  2. /// \file as_expr.hpp
  3. /// Contains definition of the as_expr\<\> and as_child\<\> helper class
  4. /// templates used to implement proto::domain's as_expr\<\> and as_child\<\>
  5. /// member templates.
  6. //
  7. // Copyright 2010 Eric Niebler. Distributed under the Boost
  8. // Software License, Version 1.0. (See accompanying file
  9. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_PROTO_DETAIL_AS_EXPR_HPP_EAN_06_09_2010
  11. #define BOOST_PROTO_DETAIL_AS_EXPR_HPP_EAN_06_09_2010
  12. #include <boost/config.hpp>
  13. #include <boost/detail/workaround.hpp>
  14. #include <boost/type_traits/remove_const.hpp>
  15. #include <boost/proto/proto_fwd.hpp>
  16. #include <boost/proto/args.hpp>
  17. namespace boost { namespace proto { namespace detail
  18. {
  19. ////////////////////////////////////////////////////////////////////////////////////////////////
  20. template<typename Generator>
  21. struct base_generator
  22. {
  23. typedef Generator type;
  24. };
  25. template<typename Generator>
  26. struct base_generator<use_basic_expr<Generator> >
  27. {
  28. typedef Generator type;
  29. };
  30. ////////////////////////////////////////////////////////////////////////////////////////////////
  31. template<typename T, typename Generator, bool WantsBasicExpr>
  32. struct as_expr;
  33. ////////////////////////////////////////////////////////////////////////////////////////////////
  34. template<typename T, typename Generator>
  35. struct as_expr<T, Generator, false>
  36. {
  37. typedef typename term_traits<T &>::value_type value_type;
  38. typedef proto::expr<proto::tag::terminal, term<value_type>, 0> expr_type;
  39. typedef typename Generator::template result<Generator(expr_type)>::type result_type;
  40. result_type operator()(T &t) const
  41. {
  42. return Generator()(expr_type::make(t));
  43. }
  44. };
  45. ////////////////////////////////////////////////////////////////////////////////////////////////
  46. template<typename T, typename Generator>
  47. struct as_expr<T, Generator, true>
  48. {
  49. typedef typename term_traits<T &>::value_type value_type;
  50. typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> expr_type;
  51. typedef typename Generator::template result<Generator(expr_type)>::type result_type;
  52. result_type operator()(T &t) const
  53. {
  54. return Generator()(expr_type::make(t));
  55. }
  56. };
  57. ////////////////////////////////////////////////////////////////////////////////////////////////
  58. template<typename T>
  59. struct as_expr<T, proto::default_generator, false>
  60. {
  61. typedef typename term_traits<T &>::value_type value_type;
  62. typedef proto::expr<proto::tag::terminal, term<value_type>, 0> result_type;
  63. result_type operator()(T &t) const
  64. {
  65. return result_type::make(t);
  66. }
  67. };
  68. ////////////////////////////////////////////////////////////////////////////////////////////////
  69. template<typename T>
  70. struct as_expr<T, proto::default_generator, true>
  71. {
  72. typedef typename term_traits<T &>::value_type value_type;
  73. typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> result_type;
  74. result_type operator()(T &t) const
  75. {
  76. return result_type::make(t);
  77. }
  78. };
  79. ////////////////////////////////////////////////////////////////////////////////////////////////
  80. template<typename T, typename Generator, bool WantsBasicExpr>
  81. struct as_child;
  82. ////////////////////////////////////////////////////////////////////////////////////////////////
  83. template<typename T, typename Generator>
  84. struct as_child<T, Generator, false>
  85. {
  86. #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  87. typedef typename term_traits<T &>::reference reference;
  88. #else
  89. typedef T &reference;
  90. #endif
  91. typedef proto::expr<proto::tag::terminal, term<reference>, 0> expr_type;
  92. typedef typename Generator::template result<Generator(expr_type)>::type result_type;
  93. result_type operator()(T &t) const
  94. {
  95. return Generator()(expr_type::make(t));
  96. }
  97. };
  98. ////////////////////////////////////////////////////////////////////////////////////////////////
  99. template<typename T, typename Generator>
  100. struct as_child<T, Generator, true>
  101. {
  102. #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  103. typedef typename term_traits<T &>::reference reference;
  104. #else
  105. typedef T &reference;
  106. #endif
  107. typedef proto::basic_expr<proto::tag::terminal, term<reference>, 0> expr_type;
  108. typedef typename Generator::template result<Generator(expr_type)>::type result_type;
  109. result_type operator()(T &t) const
  110. {
  111. return Generator()(expr_type::make(t));
  112. }
  113. };
  114. ////////////////////////////////////////////////////////////////////////////////////////////////
  115. template<typename T>
  116. struct as_child<T, proto::default_generator, false>
  117. {
  118. #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  119. typedef typename term_traits<T &>::reference reference;
  120. #else
  121. typedef T &reference;
  122. #endif
  123. typedef proto::expr<proto::tag::terminal, term<reference>, 0> result_type;
  124. result_type operator()(T &t) const
  125. {
  126. return result_type::make(t);
  127. }
  128. };
  129. ////////////////////////////////////////////////////////////////////////////////////////////////
  130. template<typename T>
  131. struct as_child<T, proto::default_generator, true>
  132. {
  133. #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  134. typedef typename term_traits<T &>::reference reference;
  135. #else
  136. typedef T &reference;
  137. #endif
  138. typedef proto::basic_expr<proto::tag::terminal, term<reference>, 0> result_type;
  139. result_type operator()(T &t) const
  140. {
  141. return result_type::make(t);
  142. }
  143. };
  144. }}}
  145. #endif