expr.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. ///////////////////////////////////////////////////////////////////////////////
  2. /// \file expr.hpp
  3. /// Contains definition of expr\<\> class template.
  4. //
  5. // Copyright 2008 Eric Niebler. Distributed under the Boost
  6. // Software License, Version 1.0. (See accompanying file
  7. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_PROTO_EXPR_HPP_EAN_04_01_2005
  9. #define BOOST_PROTO_EXPR_HPP_EAN_04_01_2005
  10. #include <boost/preprocessor/cat.hpp>
  11. #include <boost/preprocessor/arithmetic/dec.hpp>
  12. #include <boost/preprocessor/selection/max.hpp>
  13. #include <boost/preprocessor/iteration/iterate.hpp>
  14. #include <boost/preprocessor/repetition/repeat.hpp>
  15. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  16. #include <boost/preprocessor/repetition/enum_trailing.hpp>
  17. #include <boost/preprocessor/repetition/enum_params.hpp>
  18. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  19. #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
  20. #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
  21. #include <boost/utility/addressof.hpp>
  22. #include <boost/proto/proto_fwd.hpp>
  23. #include <boost/proto/args.hpp>
  24. #include <boost/proto/traits.hpp>
  25. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  26. # pragma warning(push)
  27. # pragma warning(disable : 4510) // default constructor could not be generated
  28. # pragma warning(disable : 4512) // assignment operator could not be generated
  29. # pragma warning(disable : 4610) // user defined constructor required
  30. #endif
  31. namespace boost { namespace proto
  32. {
  33. namespace detail
  34. {
  35. /// INTERNAL ONLY
  36. ///
  37. #define BOOST_PROTO_CHILD(Z, N, DATA) \
  38. typedef BOOST_PP_CAT(Arg, N) BOOST_PP_CAT(proto_child, N); \
  39. BOOST_PP_CAT(proto_child, N) BOOST_PP_CAT(child, N); \
  40. /**< INTERNAL ONLY */
  41. /// INTERNAL ONLY
  42. ///
  43. #define BOOST_PROTO_VOID(Z, N, DATA) \
  44. typedef void BOOST_PP_CAT(proto_child, N); \
  45. /**< INTERNAL ONLY */
  46. struct not_a_valid_type
  47. {
  48. private:
  49. not_a_valid_type()
  50. {}
  51. };
  52. template<typename Tag, typename Arg>
  53. struct address_of_hack
  54. {
  55. typedef not_a_valid_type type;
  56. };
  57. template<typename Expr>
  58. struct address_of_hack<proto::tag::address_of, Expr &>
  59. {
  60. typedef Expr *type;
  61. };
  62. template<typename T, typename Expr, typename Arg0>
  63. Expr make_terminal(T &t, Expr *, proto::term<Arg0> *)
  64. {
  65. Expr that = {t};
  66. return that;
  67. }
  68. template<typename T, typename Expr, typename Arg0, std::size_t N>
  69. Expr make_terminal(T (&t)[N], Expr *, proto::term<Arg0[N]> *)
  70. {
  71. Expr that;
  72. for(std::size_t i = 0; i < N; ++i)
  73. {
  74. that.child0[i] = t[i];
  75. }
  76. return that;
  77. }
  78. template<typename T, typename Expr, typename Arg0, std::size_t N>
  79. Expr make_terminal(T const(&t)[N], Expr *, proto::term<Arg0[N]> *)
  80. {
  81. Expr that;
  82. for(std::size_t i = 0; i < N; ++i)
  83. {
  84. that.child0[i] = t[i];
  85. }
  86. return that;
  87. }
  88. template<typename T, typename U>
  89. struct same_cv
  90. {
  91. typedef U type;
  92. };
  93. template<typename T, typename U>
  94. struct same_cv<T const, U>
  95. {
  96. typedef U const type;
  97. };
  98. }
  99. namespace result_of
  100. {
  101. /// \brief A helper metafunction for computing the
  102. /// return type of \c proto::expr\<\>::operator().
  103. template<typename Sig, typename This, typename Domain>
  104. struct funop;
  105. #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PP_DEC(BOOST_PROTO_MAX_FUNCTION_CALL_ARITY), <boost/proto/detail/funop.hpp>))
  106. #include BOOST_PP_ITERATE()
  107. }
  108. namespace exprns_
  109. {
  110. // The expr<> specializations are actually defined here.
  111. #define BOOST_PROTO_DEFINE_TERMINAL
  112. #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, <boost/proto/detail/expr0.hpp>))
  113. #include BOOST_PP_ITERATE()
  114. #undef BOOST_PROTO_DEFINE_TERMINAL
  115. #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/expr0.hpp>))
  116. #include BOOST_PP_ITERATE()
  117. }
  118. #undef BOOST_PROTO_CHILD
  119. #undef BOOST_PROTO_VOID
  120. /// \brief Lets you inherit the interface of an expression
  121. /// while hiding from Proto the fact that the type is a Proto
  122. /// expression.
  123. template<typename Expr>
  124. struct unexpr
  125. : Expr
  126. {
  127. BOOST_PROTO_UNEXPR()
  128. explicit unexpr(Expr const &e)
  129. : Expr(e)
  130. {}
  131. using Expr::operator =;
  132. };
  133. }}
  134. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  135. # pragma warning(pop)
  136. #endif
  137. #endif // BOOST_PROTO_EXPR_HPP_EAN_04_01_2005