expr.hpp 4.8 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/facilities/intercept.hpp>
  15. #include <boost/preprocessor/repetition/repeat.hpp>
  16. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  17. #include <boost/preprocessor/repetition/enum_trailing.hpp>
  18. #include <boost/preprocessor/repetition/enum_params.hpp>
  19. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  20. #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
  21. #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
  22. #include <boost/utility/addressof.hpp>
  23. #include <boost/proto/proto_fwd.hpp>
  24. #include <boost/proto/args.hpp>
  25. #include <boost/proto/traits.hpp>
  26. #if defined(_MSC_VER)
  27. # pragma warning(push)
  28. # pragma warning(disable : 4510) // default constructor could not be generated
  29. # pragma warning(disable : 4512) // assignment operator could not be generated
  30. # pragma warning(disable : 4610) // user defined constructor required
  31. # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined
  32. #endif
  33. namespace boost { namespace proto
  34. {
  35. namespace detail
  36. {
  37. struct not_a_valid_type
  38. {
  39. private:
  40. not_a_valid_type()
  41. {}
  42. };
  43. template<typename Tag, typename Arg>
  44. struct address_of_hack
  45. {
  46. typedef not_a_valid_type type;
  47. };
  48. template<typename Expr>
  49. struct address_of_hack<proto::tag::address_of, Expr &>
  50. {
  51. typedef Expr *type;
  52. };
  53. template<typename T, typename Expr, typename Arg0>
  54. BOOST_FORCEINLINE
  55. Expr make_terminal(T &t, Expr *, proto::term<Arg0> *)
  56. {
  57. Expr that = {t};
  58. return that;
  59. }
  60. template<typename T, typename Expr, typename Arg0, std::size_t N>
  61. BOOST_FORCEINLINE
  62. Expr make_terminal(T (&t)[N], Expr *, proto::term<Arg0[N]> *)
  63. {
  64. Expr that;
  65. for(std::size_t i = 0; i < N; ++i)
  66. {
  67. that.child0[i] = t[i];
  68. }
  69. return that;
  70. }
  71. template<typename T, typename Expr, typename Arg0, std::size_t N>
  72. BOOST_FORCEINLINE
  73. Expr make_terminal(T const(&t)[N], Expr *, proto::term<Arg0[N]> *)
  74. {
  75. Expr that;
  76. for(std::size_t i = 0; i < N; ++i)
  77. {
  78. that.child0[i] = t[i];
  79. }
  80. return that;
  81. }
  82. // Work-around for:
  83. // https://connect.microsoft.com/VisualStudio/feedback/details/765449/codegen-stack-corruption-using-runtime-checks-when-aggregate-initializing-struct
  84. #if BOOST_WORKAROUND(BOOST_MSVC, < 1800)
  85. template<typename T, typename Expr, typename C, typename U>
  86. BOOST_FORCEINLINE
  87. Expr make_terminal(T &t, Expr *, proto::term<U C::*> *)
  88. {
  89. Expr that;
  90. that.child0 = t;
  91. return that;
  92. }
  93. #endif
  94. template<typename T, typename U>
  95. struct same_cv
  96. {
  97. typedef U type;
  98. };
  99. template<typename T, typename U>
  100. struct same_cv<T const, U>
  101. {
  102. typedef U const type;
  103. };
  104. }
  105. namespace result_of
  106. {
  107. /// \brief A helper metafunction for computing the
  108. /// return type of \c proto::expr\<\>::operator().
  109. template<typename Sig, typename This, typename Domain>
  110. struct funop;
  111. #include <boost/proto/detail/funop.hpp>
  112. }
  113. namespace exprns_
  114. {
  115. // This is where the basic_expr specializations are
  116. // actually defined:
  117. #include <boost/proto/detail/basic_expr.hpp>
  118. // This is where the expr specialization are
  119. // actually defined:
  120. #include <boost/proto/detail/expr.hpp>
  121. }
  122. /// \brief Lets you inherit the interface of an expression
  123. /// while hiding from Proto the fact that the type is a Proto
  124. /// expression.
  125. template<typename Expr>
  126. struct unexpr
  127. : Expr
  128. {
  129. BOOST_PROTO_UNEXPR()
  130. BOOST_FORCEINLINE
  131. explicit unexpr(Expr const &e)
  132. : Expr(e)
  133. {}
  134. using Expr::operator =;
  135. };
  136. }}
  137. #if defined(_MSC_VER)
  138. # pragma warning(pop)
  139. #endif
  140. #endif // BOOST_PROTO_EXPR_HPP_EAN_04_01_2005