make_tuple_indices.hpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // Copyright (C) 2012-2013 Vicente J. Botet Escriba
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // 2013/04 Vicente J. Botet Escriba
  6. // Provide implementation up to 10 parameters when BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined.
  7. // 2012/11 Vicente J. Botet Escriba
  8. // Adapt to boost libc++ implementation
  9. //===----------------------------------------------------------------------===//
  10. //
  11. // The LLVM Compiler Infrastructure
  12. //
  13. // This file is dual licensed under the MIT and the University of Illinois Open
  14. // Source Licenses. See LICENSE.TXT for details.
  15. //
  16. // The make_tuple_indices C++11 code is based on the one from libcxx.
  17. //===----------------------------------------------------------------------===//
  18. #ifndef BOOST_THREAD_DETAIL_MAKE_TUPLE_INDICES_HPP
  19. #define BOOST_THREAD_DETAIL_MAKE_TUPLE_INDICES_HPP
  20. #include <boost/config.hpp>
  21. #include <boost/static_assert.hpp>
  22. namespace boost
  23. {
  24. namespace detail
  25. {
  26. #if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  27. // make_tuple_indices
  28. template <std::size_t...> struct tuple_indices
  29. {};
  30. template <std::size_t Sp, class IntTuple, std::size_t Ep>
  31. struct make_indices_imp;
  32. template <std::size_t Sp, std::size_t ...Indices, std::size_t Ep>
  33. struct make_indices_imp<Sp, tuple_indices<Indices...>, Ep>
  34. {
  35. typedef typename make_indices_imp<Sp+1, tuple_indices<Indices..., Sp>, Ep>::type type;
  36. };
  37. template <std::size_t Ep, std::size_t ...Indices>
  38. struct make_indices_imp<Ep, tuple_indices<Indices...>, Ep>
  39. {
  40. typedef tuple_indices<Indices...> type;
  41. };
  42. template <std::size_t Ep, std::size_t Sp = 0>
  43. struct make_tuple_indices
  44. {
  45. BOOST_STATIC_ASSERT_MSG(Sp <= Ep, "make_tuple_indices input error");
  46. typedef typename make_indices_imp<Sp, tuple_indices<>, Ep>::type type;
  47. };
  48. #else
  49. // - tuple forward declaration -----------------------------------------------
  50. template <
  51. std::size_t T0 = 0, std::size_t T1 = 0, std::size_t T2 = 0,
  52. std::size_t T3 = 0, std::size_t T4 = 0, std::size_t T5 = 0,
  53. std::size_t T6 = 0, std::size_t T7 = 0, std::size_t T8 = 0,
  54. std::size_t T9 = 0>
  55. class tuple_indices {};
  56. template <std::size_t Sp, class IntTuple, std::size_t Ep>
  57. struct make_indices_imp;
  58. template <std::size_t Sp, std::size_t Ep>
  59. struct make_indices_imp<Sp, tuple_indices<>, Ep>
  60. {
  61. typedef typename make_indices_imp<Sp+1, tuple_indices<Sp>, Ep>::type type;
  62. };
  63. template <std::size_t Sp, std::size_t I0, std::size_t Ep>
  64. struct make_indices_imp<Sp, tuple_indices<I0>, Ep>
  65. {
  66. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, Sp>, Ep>::type type;
  67. };
  68. template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t Ep>
  69. struct make_indices_imp<Sp, tuple_indices<I0, I1>, Ep>
  70. {
  71. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, Sp>, Ep>::type type;
  72. };
  73. template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t Ep>
  74. struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2>, Ep>
  75. {
  76. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, Sp>, Ep>::type type;
  77. };
  78. template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t Ep>
  79. struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3>, Ep>
  80. {
  81. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, Sp>, Ep>::type type;
  82. };
  83. template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t Ep>
  84. struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4>, Ep>
  85. {
  86. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, Sp>, Ep>::type type;
  87. };
  88. template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5, std::size_t Ep>
  89. struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5>, Ep>
  90. {
  91. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, Sp>, Ep>::type type;
  92. };
  93. template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
  94. , std::size_t I6
  95. , std::size_t Ep>
  96. struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5, I6>, Ep>
  97. {
  98. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, I6, Sp>, Ep>::type type;
  99. };
  100. template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
  101. , std::size_t I6
  102. , std::size_t I7
  103. , std::size_t Ep>
  104. struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5, I6, I7>, Ep>
  105. {
  106. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, Sp>, Ep>::type type;
  107. };
  108. template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
  109. , std::size_t I6
  110. , std::size_t I7
  111. , std::size_t I8
  112. , std::size_t Ep>
  113. struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5, I6, I7, I8>, Ep>
  114. {
  115. typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8, Sp>, Ep>::type type;
  116. };
  117. // template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
  118. // , std::size_t I6
  119. // , std::size_t I7
  120. // , std::size_t I8
  121. // , std::size_t I9
  122. // , std::size_t Ep>
  123. // struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5, I6, I7, I8, I9>, Ep>
  124. // {
  125. // typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, Sp>, Ep>::type type;
  126. // };
  127. template <std::size_t Ep>
  128. struct make_indices_imp<Ep, tuple_indices<>, Ep>
  129. {
  130. typedef tuple_indices<> type;
  131. };
  132. template <std::size_t Ep, std::size_t I0>
  133. struct make_indices_imp<Ep, tuple_indices<I0>, Ep>
  134. {
  135. typedef tuple_indices<I0> type;
  136. };
  137. template <std::size_t Ep, std::size_t I0, std::size_t I1>
  138. struct make_indices_imp<Ep, tuple_indices<I0, I1>, Ep>
  139. {
  140. typedef tuple_indices<I0, I1> type;
  141. };
  142. template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2>
  143. struct make_indices_imp<Ep, tuple_indices<I0, I1, I2>, Ep>
  144. {
  145. typedef tuple_indices<I0, I1, I2> type;
  146. };
  147. template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3>
  148. struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3>, Ep>
  149. {
  150. typedef tuple_indices<I0, I1, I2, I3> type;
  151. };
  152. template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4>
  153. struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4>, Ep>
  154. {
  155. typedef tuple_indices<I0, I1, I2, I3, I4> type;
  156. };
  157. template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5>
  158. struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5>, Ep>
  159. {
  160. typedef tuple_indices<I0, I1, I2, I3, I4, I5> type;
  161. };
  162. template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
  163. , std::size_t I6
  164. >
  165. struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5, I6>, Ep>
  166. {
  167. typedef tuple_indices<I0, I1, I2, I3, I4, I5, I6> type;
  168. };
  169. template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
  170. , std::size_t I6
  171. , std::size_t I7
  172. >
  173. struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7>, Ep>
  174. {
  175. typedef tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7> type;
  176. };
  177. template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
  178. , std::size_t I6
  179. , std::size_t I7
  180. , std::size_t I8
  181. >
  182. struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8>, Ep>
  183. {
  184. typedef tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8> type;
  185. };
  186. template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
  187. , std::size_t I6
  188. , std::size_t I7
  189. , std::size_t I8
  190. , std::size_t I9
  191. >
  192. struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8, I9>, Ep>
  193. {
  194. typedef tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8, I9> type;
  195. };
  196. template <std::size_t Ep, std::size_t Sp = 0>
  197. struct make_tuple_indices
  198. {
  199. BOOST_STATIC_ASSERT_MSG(Sp <= Ep, "make_tuple_indices input error");
  200. typedef typename make_indices_imp<Sp, tuple_indices<>, Ep>::type type;
  201. };
  202. #endif
  203. }
  204. }
  205. #endif // header