vector_n.hpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  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. ==============================================================================*/
  6. // No include guard. This file is meant to be included many times
  7. #if !defined(FUSION_MACRO_05042005)
  8. #define FUSION_MACRO_05042005
  9. #define FUSION_VECTOR_CTOR_DEFAULT_INIT(z, n, _) \
  10. m##n()
  11. #define FUSION_VECTOR_CTOR_INIT(z, n, _) \
  12. m##n(_##n)
  13. #define FUSION_VECTOR_MEMBER_CTOR_INIT(z, n, _) \
  14. m##n(other.m##n)
  15. #define FUSION_VECTOR_CTOR_FORWARD(z, n, _) \
  16. m##n(BOOST_FUSION_FWD_ELEM(T##n, other.m##n))
  17. #define FUSION_VECTOR_CTOR_ARG_FWD(z, n, _) \
  18. m##n(BOOST_FUSION_FWD_ELEM(U##n, _##n))
  19. #define FUSION_VECTOR_MEMBER_DECL(z, n, _) \
  20. T##n m##n;
  21. #define FUSION_VECTOR_MEMBER_FORWARD(z, n, _) \
  22. BOOST_FUSION_FWD_ELEM(U##n, _##n)
  23. #define FUSION_VECTOR_MEMBER_ASSIGN(z, n, _) \
  24. this->BOOST_PP_CAT(m, n) = vec.BOOST_PP_CAT(m, n);
  25. #define FUSION_VECTOR_MEMBER_DEREF_ASSIGN(z, n, _) \
  26. this->BOOST_PP_CAT(m, n) = *BOOST_PP_CAT(i, n);
  27. #define FUSION_VECTOR_MEMBER_MOVE(z, n, _) \
  28. this->BOOST_PP_CAT(m, n) = std::forward< \
  29. BOOST_PP_CAT(T, n)>(vec.BOOST_PP_CAT(m, n));
  30. #define FUSION_VECTOR_MEMBER_AT_IMPL(z, n, _) \
  31. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED \
  32. typename add_reference<T##n>::type \
  33. at_impl(mpl::int_<n>) { return this->m##n; } \
  34. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED \
  35. typename add_reference<typename add_const<T##n>::type>::type \
  36. at_impl(mpl::int_<n>) const { return this->m##n; }
  37. #define FUSION_VECTOR_MEMBER_ITER_DECL_VAR(z, n, _) \
  38. typedef typename result_of::next< \
  39. BOOST_PP_CAT(I, BOOST_PP_DEC(n))>::type BOOST_PP_CAT(I, n); \
  40. BOOST_PP_CAT(I, n) BOOST_PP_CAT(i, n) \
  41. = fusion::next(BOOST_PP_CAT(i, BOOST_PP_DEC(n)));
  42. #endif
  43. #define N BOOST_PP_ITERATION()
  44. template <BOOST_PP_ENUM_PARAMS(N, typename T)>
  45. struct BOOST_PP_CAT(vector_data, N)
  46. {
  47. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  48. BOOST_PP_CAT(vector_data, N)()
  49. : BOOST_PP_ENUM(N, FUSION_VECTOR_CTOR_DEFAULT_INIT, _) {}
  50. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  51. FUSION_HASH if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  52. #endif
  53. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
  54. (defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES))
  55. template <BOOST_PP_ENUM_PARAMS(N, typename U)>
  56. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  57. FUSION_HASH if !defined(BOOST_CLANG)
  58. BOOST_CXX14_CONSTEXPR
  59. FUSION_HASH endif
  60. #else
  61. #if !defined(BOOST_CLANG)
  62. BOOST_CXX14_CONSTEXPR
  63. #endif
  64. #endif
  65. BOOST_FUSION_GPU_ENABLED
  66. BOOST_PP_CAT(vector_data, N)(BOOST_PP_ENUM_BINARY_PARAMS(N, U, && arg)
  67. , typename boost::enable_if<is_convertible<U0, T0> >::type* /*dummy*/ = 0
  68. )
  69. : BOOST_PP_ENUM(N, FUSION_VECTOR_CTOR_ARG_FWD, arg) {}
  70. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  71. BOOST_PP_CAT(vector_data, N)(
  72. BOOST_PP_CAT(vector_data, N)&& other)
  73. : BOOST_PP_ENUM(N, FUSION_VECTOR_CTOR_FORWARD, arg) {}
  74. #endif
  75. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  76. FUSION_HASH endif
  77. #endif
  78. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  79. FUSION_HASH if !defined(BOOST_CLANG)
  80. BOOST_CONSTEXPR
  81. FUSION_HASH endif
  82. #else
  83. #if !defined(BOOST_CLANG)
  84. BOOST_CONSTEXPR
  85. #endif
  86. #endif
  87. BOOST_FUSION_GPU_ENABLED
  88. BOOST_PP_CAT(vector_data, N)(
  89. BOOST_PP_ENUM_BINARY_PARAMS(
  90. N, typename detail::call_param<T, >::type arg))
  91. : BOOST_PP_ENUM(N, FUSION_VECTOR_CTOR_INIT, arg) {}
  92. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  93. BOOST_PP_CAT(vector_data, N)(
  94. BOOST_PP_CAT(vector_data, N) const& other)
  95. : BOOST_PP_ENUM(N, FUSION_VECTOR_MEMBER_CTOR_INIT, _) {}
  96. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  97. BOOST_PP_CAT(vector_data, N)&
  98. operator=(BOOST_PP_CAT(vector_data, N) const& vec)
  99. {
  100. BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_ASSIGN, _)
  101. return *this;
  102. }
  103. template <typename Sequence>
  104. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  105. FUSION_HASH if !defined(BOOST_CLANG)
  106. BOOST_CXX14_CONSTEXPR
  107. FUSION_HASH endif
  108. #else
  109. #if !defined(BOOST_CLANG)
  110. BOOST_CXX14_CONSTEXPR
  111. #endif
  112. #endif
  113. BOOST_FUSION_GPU_ENABLED
  114. static BOOST_PP_CAT(vector_data, N)
  115. init_from_sequence(Sequence const& seq)
  116. {
  117. typedef typename result_of::begin<Sequence const>::type I0;
  118. I0 i0 = fusion::begin(seq);
  119. BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_VECTOR_MEMBER_ITER_DECL_VAR, _)
  120. return BOOST_PP_CAT(vector_data, N)(BOOST_PP_ENUM_PARAMS(N, *i));
  121. }
  122. template <typename Sequence>
  123. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  124. FUSION_HASH if !defined(BOOST_CLANG)
  125. BOOST_CXX14_CONSTEXPR
  126. FUSION_HASH endif
  127. #else
  128. #if !defined(BOOST_CLANG)
  129. BOOST_CXX14_CONSTEXPR
  130. #endif
  131. #endif
  132. BOOST_FUSION_GPU_ENABLED
  133. static BOOST_PP_CAT(vector_data, N)
  134. init_from_sequence(Sequence& seq)
  135. {
  136. typedef typename result_of::begin<Sequence>::type I0;
  137. I0 i0 = fusion::begin(seq);
  138. BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_VECTOR_MEMBER_ITER_DECL_VAR, _)
  139. return BOOST_PP_CAT(vector_data, N)(BOOST_PP_ENUM_PARAMS(N, *i));
  140. }
  141. BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_DECL, _)
  142. };
  143. template <BOOST_PP_ENUM_PARAMS(N, typename T)>
  144. struct BOOST_PP_CAT(vector, N)
  145. : BOOST_PP_CAT(vector_data, N)<BOOST_PP_ENUM_PARAMS(N, T)>
  146. , sequence_base<BOOST_PP_CAT(vector, N)<BOOST_PP_ENUM_PARAMS(N, T)> >
  147. {
  148. typedef BOOST_PP_CAT(vector, N)<BOOST_PP_ENUM_PARAMS(N, T)> this_type;
  149. typedef BOOST_PP_CAT(vector_data, N)<BOOST_PP_ENUM_PARAMS(N, T)> base_type;
  150. typedef mpl::BOOST_PP_CAT(vector, N)<BOOST_PP_ENUM_PARAMS(N, T)> types;
  151. typedef vector_tag fusion_tag;
  152. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  153. typedef mpl::false_ is_view;
  154. typedef random_access_traversal_tag category;
  155. typedef mpl::int_<N> size;
  156. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  157. BOOST_PP_CAT(vector, N)() {}
  158. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  159. FUSION_HASH if !defined(BOOST_CLANG)
  160. BOOST_CONSTEXPR
  161. FUSION_HASH endif
  162. #else
  163. #if !defined(BOOST_CLANG)
  164. BOOST_CONSTEXPR
  165. #endif
  166. #endif
  167. BOOST_FUSION_GPU_ENABLED
  168. #if (N == 1)
  169. explicit
  170. #endif
  171. BOOST_PP_CAT(vector, N)(
  172. BOOST_PP_ENUM_BINARY_PARAMS(
  173. N, typename detail::call_param<T, >::type arg))
  174. : base_type(BOOST_PP_ENUM_PARAMS(N, arg)) {}
  175. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  176. FUSION_HASH if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  177. #endif
  178. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
  179. (defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES))
  180. template <BOOST_PP_ENUM_PARAMS(N, typename U)>
  181. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  182. FUSION_HASH if !defined(BOOST_CLANG)
  183. BOOST_CXX14_CONSTEXPR
  184. FUSION_HASH endif
  185. #else
  186. #if !defined(BOOST_CLANG)
  187. BOOST_CXX14_CONSTEXPR
  188. #endif
  189. #endif
  190. BOOST_FUSION_GPU_ENABLED
  191. #if (N == 1)
  192. explicit
  193. BOOST_PP_CAT(vector, N)(U0&& _0
  194. , typename boost::enable_if<is_convertible<U0, T0> >::type* /*dummy*/ = 0
  195. )
  196. : base_type(BOOST_FUSION_FWD_ELEM(U0, _0)) {}
  197. #else
  198. BOOST_PP_CAT(vector, N)(BOOST_PP_ENUM_BINARY_PARAMS(N, U, && arg))
  199. : base_type(BOOST_PP_ENUM(N, FUSION_VECTOR_MEMBER_FORWARD, arg)) {}
  200. #endif
  201. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  202. BOOST_PP_CAT(vector, N)(BOOST_PP_CAT(vector, N)&& rhs)
  203. : base_type(std::forward<base_type>(rhs)) {}
  204. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  205. BOOST_PP_CAT(vector, N)(BOOST_PP_CAT(vector, N) const& rhs)
  206. : base_type(static_cast<base_type const&>(rhs)) {}
  207. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  208. BOOST_PP_CAT(vector, N)&
  209. operator=(BOOST_PP_CAT(vector, N) const& vec)
  210. {
  211. base_type::operator=(vec);
  212. return *this;
  213. }
  214. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  215. BOOST_PP_CAT(vector, N)&
  216. operator=(BOOST_PP_CAT(vector, N)&& vec)
  217. {
  218. BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_MOVE, _)
  219. return *this;
  220. }
  221. #endif
  222. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  223. FUSION_HASH endif
  224. #endif
  225. template <BOOST_PP_ENUM_PARAMS(N, typename U)>
  226. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  227. FUSION_HASH if !defined(BOOST_CLANG)
  228. BOOST_CXX14_CONSTEXPR
  229. FUSION_HASH endif
  230. #else
  231. #if !defined(BOOST_CLANG)
  232. BOOST_CXX14_CONSTEXPR
  233. #endif
  234. #endif
  235. BOOST_FUSION_GPU_ENABLED
  236. BOOST_PP_CAT(vector, N)(
  237. BOOST_PP_CAT(vector, N)<BOOST_PP_ENUM_PARAMS(N, U)> const& vec)
  238. : base_type(BOOST_PP_ENUM_PARAMS(N, vec.m)) {}
  239. template <typename Sequence>
  240. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  241. FUSION_HASH if !defined(BOOST_CLANG)
  242. BOOST_CXX14_CONSTEXPR
  243. FUSION_HASH endif
  244. #else
  245. #if !defined(BOOST_CLANG)
  246. BOOST_CXX14_CONSTEXPR
  247. #endif
  248. #endif
  249. BOOST_FUSION_GPU_ENABLED
  250. BOOST_PP_CAT(vector, N)(
  251. Sequence const& seq
  252. , typename boost::enable_if<traits::is_sequence<Sequence> >::type* = 0
  253. #if (N == 1)
  254. , typename boost::disable_if<is_convertible<Sequence, T0> >::type* /*dummy*/ = 0
  255. #endif
  256. )
  257. : base_type(base_type::init_from_sequence(seq)) {}
  258. template <typename Sequence>
  259. #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
  260. FUSION_HASH if !defined(BOOST_CLANG)
  261. BOOST_CXX14_CONSTEXPR
  262. FUSION_HASH endif
  263. #else
  264. #if !defined(BOOST_CLANG)
  265. BOOST_CXX14_CONSTEXPR
  266. #endif
  267. #endif
  268. BOOST_FUSION_GPU_ENABLED
  269. BOOST_PP_CAT(vector, N)(
  270. Sequence& seq
  271. , typename boost::enable_if<traits::is_sequence<Sequence> >::type* = 0
  272. #if (N == 1)
  273. , typename boost::disable_if<is_convertible<Sequence, T0> >::type* /*dummy*/ = 0
  274. #endif
  275. )
  276. : base_type(base_type::init_from_sequence(seq)) {}
  277. template <BOOST_PP_ENUM_PARAMS(N, typename U)>
  278. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  279. BOOST_PP_CAT(vector, N)&
  280. operator=(BOOST_PP_CAT(vector, N)<BOOST_PP_ENUM_PARAMS(N, U)> const& vec)
  281. {
  282. BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_ASSIGN, _)
  283. return *this;
  284. }
  285. template <typename Sequence>
  286. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  287. typename boost::disable_if<is_convertible<Sequence, T0>, this_type&>::type
  288. operator=(Sequence const& seq)
  289. {
  290. typedef typename result_of::begin<Sequence const>::type I0;
  291. I0 i0 = fusion::begin(seq);
  292. BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_VECTOR_MEMBER_ITER_DECL_VAR, _)
  293. BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_DEREF_ASSIGN, _)
  294. return *this;
  295. }
  296. BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_AT_IMPL, _)
  297. template<typename I>
  298. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  299. typename add_reference<typename mpl::at<types, I>::type>::type
  300. at_impl(I)
  301. {
  302. return this->at_impl(mpl::int_<I::value>());
  303. }
  304. template<typename I>
  305. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  306. typename add_reference<typename add_const<typename mpl::at<types, I>::type>::type>::type
  307. at_impl(I) const
  308. {
  309. return this->at_impl(mpl::int_<I::value>());
  310. }
  311. };
  312. #undef N