args.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #ifndef BOOST_PP_IS_ITERATING
  2. ///////////////////////////////////////////////////////////////////////////////
  3. /// \file args.hpp
  4. /// Contains definition of \c term\<\>, \c list1\<\>, \c list2\<\>, ...
  5. /// class templates.
  6. //
  7. // Copyright 2008 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_ARGS_HPP_EAN_04_01_2005
  11. #define BOOST_PROTO_ARGS_HPP_EAN_04_01_2005
  12. #include <iosfwd>
  13. #include <boost/config.hpp>
  14. #include <boost/detail/workaround.hpp>
  15. #include <boost/preprocessor/cat.hpp>
  16. #include <boost/preprocessor/arithmetic/dec.hpp>
  17. #include <boost/preprocessor/iteration/iterate.hpp>
  18. #include <boost/preprocessor/repetition/enum_params.hpp>
  19. #include <boost/preprocessor/repetition/repeat.hpp>
  20. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  21. #include <boost/type_traits/is_function.hpp>
  22. #include <boost/type_traits/is_abstract.hpp>
  23. #include <boost/type_traits/is_base_of.hpp>
  24. #include <boost/mpl/if.hpp>
  25. #include <boost/mpl/or.hpp>
  26. #include <boost/mpl/void.hpp>
  27. #include <boost/proto/proto_fwd.hpp>
  28. namespace boost { namespace proto
  29. {
  30. namespace detail
  31. {
  32. /// INTERNAL ONLY
  33. template<typename T>
  34. struct ref_only
  35. : mpl::or_<
  36. is_function<T>
  37. , is_abstract<T>
  38. , is_base_of<std::ios_base, T>
  39. >
  40. {};
  41. /// INTERNAL ONLY
  42. template<typename Expr>
  43. struct expr_traits
  44. {
  45. typedef Expr value_type;
  46. typedef Expr &reference;
  47. typedef Expr const &const_reference;
  48. };
  49. /// INTERNAL ONLY
  50. template<typename Expr>
  51. struct expr_traits<Expr &>
  52. {
  53. typedef Expr value_type;
  54. typedef Expr &reference;
  55. typedef Expr &const_reference;
  56. };
  57. /// INTERNAL ONLY
  58. template<typename Expr>
  59. struct expr_traits<Expr const &>
  60. {
  61. typedef Expr value_type;
  62. typedef Expr const &reference;
  63. typedef Expr const &const_reference;
  64. };
  65. /// INTERNAL ONLY
  66. template<typename T>
  67. struct term_traits
  68. {
  69. typedef T value_type;
  70. typedef T &reference;
  71. typedef T const &const_reference;
  72. };
  73. /// INTERNAL ONLY
  74. template<typename T>
  75. struct term_traits<T &>
  76. {
  77. typedef typename mpl::if_c<ref_only<T>::value, T &, T>::type value_type;
  78. typedef T &reference;
  79. typedef T &const_reference;
  80. };
  81. /// INTERNAL ONLY
  82. template<typename T>
  83. struct term_traits<T const &>
  84. {
  85. typedef T value_type;
  86. typedef T const &reference;
  87. typedef T const &const_reference;
  88. };
  89. /// INTERNAL ONLY
  90. template<typename T, std::size_t N>
  91. struct term_traits<T (&)[N]>
  92. {
  93. typedef T value_type[N];
  94. typedef T (&reference)[N];
  95. typedef T (&const_reference)[N];
  96. };
  97. /// INTERNAL ONLY
  98. template<typename T, std::size_t N>
  99. struct term_traits<T const (&)[N]>
  100. {
  101. typedef T value_type[N];
  102. typedef T const (&reference)[N];
  103. typedef T const (&const_reference)[N];
  104. };
  105. /// INTERNAL ONLY
  106. template<typename T, std::size_t N>
  107. struct term_traits<T[N]>
  108. {
  109. typedef T value_type[N];
  110. typedef T (&reference)[N];
  111. typedef T const (&const_reference)[N];
  112. };
  113. /// INTERNAL ONLY
  114. template<typename T, std::size_t N>
  115. struct term_traits<T const[N]>
  116. {
  117. typedef T value_type[N];
  118. typedef T const (&reference)[N];
  119. typedef T const (&const_reference)[N];
  120. };
  121. }
  122. ////////////////////////////////////////////////////////////////////////////////////////////
  123. #define BOOST_PROTO_DEFINE_CHILD_N(Z, N, DATA) \
  124. typedef BOOST_PP_CAT(Arg, N) BOOST_PP_CAT(child, N); \
  125. /**< INTERNAL ONLY */
  126. #define BOOST_PROTO_DEFINE_VOID_N(z, n, data) \
  127. typedef mpl::void_ BOOST_PP_CAT(child, n); \
  128. /**< INTERNAL ONLY */
  129. namespace argsns_
  130. {
  131. /// \brief A type sequence, for use as the 2nd parameter to the \c expr\<\> class template.
  132. ///
  133. /// A type sequence, for use as the 2nd parameter to the \c expr\<\> class template.
  134. /// The types in the sequence correspond to the children of a node in an expression tree.
  135. template< typename Arg0 >
  136. struct term
  137. {
  138. BOOST_STATIC_CONSTANT(long, arity = 0);
  139. typedef Arg0 child0;
  140. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
  141. BOOST_PP_REPEAT_FROM_TO(1, BOOST_PROTO_MAX_ARITY, BOOST_PROTO_DEFINE_VOID_N, ~)
  142. #endif
  143. /// INTERNAL ONLY
  144. ///
  145. typedef Arg0 back_;
  146. };
  147. #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/args.hpp>))
  148. #include BOOST_PP_ITERATE()
  149. #undef BOOST_PROTO_DEFINE_CHILD_N
  150. }
  151. ////////////////////////////////////////////////////////////////////////////////////////////
  152. }}
  153. #endif
  154. #else
  155. #define N BOOST_PP_ITERATION()
  156. /// \brief A type sequence, for use as the 2nd parameter to the \c expr\<\> class template.
  157. ///
  158. /// A type sequence, for use as the 2nd parameter to the \c expr\<\> class template.
  159. /// The types in the sequence correspond to the children of a node in an expression tree.
  160. template< BOOST_PP_ENUM_PARAMS(N, typename Arg) >
  161. struct BOOST_PP_CAT(list, N)
  162. {
  163. BOOST_STATIC_CONSTANT(long, arity = N);
  164. BOOST_PP_REPEAT(N, BOOST_PROTO_DEFINE_CHILD_N, ~)
  165. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
  166. BOOST_PP_REPEAT_FROM_TO(N, BOOST_PROTO_MAX_ARITY, BOOST_PROTO_DEFINE_VOID_N, ~)
  167. #endif
  168. /// INTERNAL ONLY
  169. ///
  170. typedef BOOST_PP_CAT(Arg, BOOST_PP_DEC(N)) back_;
  171. };
  172. #undef N
  173. #endif