tvariadic.hpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef BOOST_CONTRACT_DETAIL_TVARIADIC_HPP_
  2. #define BOOST_CONTRACT_DETAIL_TVARIADIC_HPP_
  3. // Copyright (C) 2008-2018 Lorenzo Caminiti
  4. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  5. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  6. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  7. #include <boost/config.hpp>
  8. #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
  9. #define BOOST_CONTRACT_DETAIL_TVARIADIC 0
  10. #else
  11. #define BOOST_CONTRACT_DETAIL_TVARIADIC 1
  12. #endif
  13. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  14. #include <tuple>
  15. /* CODE */
  16. namespace boost { namespace contract { namespace detail {
  17. namespace tvariadic_ {
  18. template<int...> struct indexes {};
  19. template<int N, int... I> struct indexes_of :
  20. indexes_of<N - 1, N - 1, I...> {};
  21. template<int... I> struct indexes_of<0, I...>
  22. { typedef indexes<I...> type; };
  23. } } } } // namespace
  24. #else
  25. #include <boost/preprocessor/repetition/enum.hpp>
  26. #include <boost/preprocessor/repetition/repeat.hpp>
  27. #include <boost/preprocessor/tuple/elem.hpp>
  28. #include <boost/preprocessor/punctuation/comma_if.hpp>
  29. #include <boost/preprocessor/cat.hpp>
  30. /* PRIVATE */
  31. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEM_(z, n, tuple) \
  32. BOOST_PP_CAT(tuple, n)
  33. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_(z, n, tuplevar_values) \
  34. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, tuplevar_values), n)( \
  35. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, tuplevar_values), n))
  36. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_(z, n, type_qualifier_name) \
  37. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 0, type_qualifier_name), n) \
  38. BOOST_PP_TUPLE_ELEM(3, 1, type_qualifier_name) \
  39. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 2, type_qualifier_name), n) \
  40. ;
  41. #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_(z, n, tokens) \
  42. tokens
  43. #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARG_(z, n, name) \
  44. BOOST_PP_CAT(name, n)
  45. #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAM_(z, n, type_qualifier_name) \
  46. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 0, type_qualifier_name), n) \
  47. BOOST_PP_TUPLE_ELEM(3, 1, type_qualifier_name) \
  48. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 2, type_qualifier_name), n)
  49. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAM_(z, n, name) \
  50. typename BOOST_PP_CAT(name, n)
  51. #endif
  52. /* PUBLIC */
  53. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  54. #define BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
  55. ,
  56. #else
  57. #define BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
  58. BOOST_PP_COMMA_IF(arity)
  59. #endif
  60. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  61. #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity) /* nothing */
  62. #else
  63. #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity) \
  64. BOOST_PP_COMMA_IF(arity)
  65. #endif
  66. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  67. #define BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, name) sizeof...(name)
  68. #else
  69. #define BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, name) arity
  70. #endif
  71. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  72. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, name) \
  73. typename... name
  74. #else
  75. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, name) \
  76. BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAM_, \
  77. name)
  78. #endif
  79. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  80. #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z( \
  81. z, arity, type, qualifier, name) \
  82. type qualifier ... name
  83. #else
  84. #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z( \
  85. z, arity, type, qualifier, name) \
  86. BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAM_, \
  87. (type, qualifier, name))
  88. #endif
  89. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  90. #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, name) \
  91. name...
  92. #else
  93. #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, name) \
  94. BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_ARG_, name)
  95. #endif
  96. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  97. #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity, tokens) \
  98. /* nothing */
  99. #else
  100. #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity, tokens) \
  101. BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_, \
  102. tokens)
  103. #endif
  104. // Tuple.
  105. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  106. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_Z( \
  107. z, arity, type, qualifier, name) \
  108. std::tuple<type qualifier ...> name;
  109. #else
  110. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_Z( \
  111. z, arity, type, qualifier, name) \
  112. BOOST_PP_REPEAT_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_, \
  113. (type, qualifier, name))
  114. #endif
  115. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  116. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(z, \
  117. arity, tuple, values) \
  118. tuple(values...)
  119. #else
  120. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(z, \
  121. arity, tuple, values) \
  122. BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_,\
  123. (tuple, values))
  124. #endif
  125. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  126. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(indexes) \
  127. int... indexes
  128. #else
  129. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(indexes) \
  130. /* nothing */
  131. #endif
  132. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  133. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(_indexes) \
  134. boost::contract::detail::tvariadic_::indexes<_indexes...>
  135. #else
  136. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(_indexes) \
  137. /* nothing */
  138. #endif
  139. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  140. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF(tuple_type) \
  141. typename boost::contract::detail::tvariadic_::indexes_of< \
  142. sizeof...(tuple_type)>::type()
  143. #else
  144. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF(unused) \
  145. /* nothing */
  146. #endif
  147. #if BOOST_CONTRACT_DETAIL_TVARIADIC
  148. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEMS_Z( \
  149. z, arity, indexes, tuple) \
  150. std::get<indexes>(tuple)...
  151. #else
  152. #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEMS_Z( \
  153. z, arity, indexes, tuple) \
  154. BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEM_,\
  155. tuple)
  156. #endif
  157. #endif // #include guard