list.hpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. #ifndef BOOST_MP11_LIST_HPP_INCLUDED
  2. #define BOOST_MP11_LIST_HPP_INCLUDED
  3. // Copyright 2015-2023 Peter Dimov.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. //
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. #include <boost/mp11/integral.hpp>
  10. #include <boost/mp11/detail/mp_list.hpp>
  11. #include <boost/mp11/detail/mp_list_v.hpp>
  12. #include <boost/mp11/detail/mp_is_list.hpp>
  13. #include <boost/mp11/detail/mp_is_value_list.hpp>
  14. #include <boost/mp11/detail/mp_front.hpp>
  15. #include <boost/mp11/detail/mp_rename.hpp>
  16. #include <boost/mp11/detail/mp_append.hpp>
  17. #include <boost/mp11/detail/config.hpp>
  18. #include <type_traits>
  19. #if defined(_MSC_VER) || defined(__GNUC__)
  20. # pragma push_macro( "I" )
  21. # undef I
  22. #endif
  23. namespace boost
  24. {
  25. namespace mp11
  26. {
  27. // mp_list<T...>
  28. // in detail/mp_list.hpp
  29. // mp_list_c<T, I...>
  30. template<class T, T... I> using mp_list_c = mp_list<std::integral_constant<T, I>...>;
  31. // mp_list_v<A...>
  32. // in detail/mp_list_v.hpp
  33. // mp_is_list<L>
  34. // in detail/mp_is_list.hpp
  35. // mp_is_value_list<L>
  36. // in detail/mp_is_value_list.hpp
  37. // mp_size<L>
  38. namespace detail
  39. {
  40. template<class L> struct mp_size_impl
  41. {
  42. // An error "no type named 'type'" here means that the argument to mp_size is not a list
  43. };
  44. template<template<class...> class L, class... T> struct mp_size_impl<L<T...>>
  45. {
  46. using type = mp_size_t<sizeof...(T)>;
  47. };
  48. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  49. template<template<auto...> class L, auto... A> struct mp_size_impl<L<A...>>
  50. {
  51. using type = mp_size_t<sizeof...(A)>;
  52. };
  53. #endif
  54. } // namespace detail
  55. template<class L> using mp_size = typename detail::mp_size_impl<L>::type;
  56. // mp_empty<L>
  57. template<class L> using mp_empty = mp_bool< mp_size<L>::value == 0 >;
  58. // mp_assign<L1, L2>
  59. namespace detail
  60. {
  61. template<class L1, class L2> struct mp_assign_impl
  62. {
  63. // An error "no type named 'type'" here means that the arguments to mp_assign aren't lists
  64. };
  65. template<template<class...> class L1, class... T, template<class...> class L2, class... U> struct mp_assign_impl<L1<T...>, L2<U...>>
  66. {
  67. using type = L1<U...>;
  68. };
  69. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  70. template<template<auto...> class L1, auto... A, template<class...> class L2, class... U> struct mp_assign_impl<L1<A...>, L2<U...>>
  71. {
  72. using type = L1<U::value...>;
  73. };
  74. template<template<class...> class L1, class... T, template<auto...> class L2, auto... B> struct mp_assign_impl<L1<T...>, L2<B...>>
  75. {
  76. using type = L1<mp_value<B>...>;
  77. };
  78. template<template<auto...> class L1, auto... A, template<auto...> class L2, auto... B> struct mp_assign_impl<L1<A...>, L2<B...>>
  79. {
  80. using type = L1<B...>;
  81. };
  82. #endif
  83. } // namespace detail
  84. template<class L1, class L2> using mp_assign = typename detail::mp_assign_impl<L1, L2>::type;
  85. // mp_clear<L>
  86. template<class L> using mp_clear = mp_assign<L, mp_list<>>;
  87. // mp_front<L>
  88. // in detail/mp_front.hpp
  89. // mp_pop_front<L>
  90. namespace detail
  91. {
  92. template<class L> struct mp_pop_front_impl
  93. {
  94. // An error "no type named 'type'" here means that the argument to mp_pop_front
  95. // is either not a list, or is an empty list
  96. };
  97. template<template<class...> class L, class T1, class... T> struct mp_pop_front_impl<L<T1, T...>>
  98. {
  99. using type = L<T...>;
  100. };
  101. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  102. template<template<auto...> class L, auto A1, auto... A> struct mp_pop_front_impl<L<A1, A...>>
  103. {
  104. using type = L<A...>;
  105. };
  106. #endif
  107. } // namespace detail
  108. template<class L> using mp_pop_front = typename detail::mp_pop_front_impl<L>::type;
  109. // mp_first<L>
  110. template<class L> using mp_first = mp_front<L>;
  111. // mp_rest<L>
  112. template<class L> using mp_rest = mp_pop_front<L>;
  113. // mp_second<L>
  114. namespace detail
  115. {
  116. template<class L> struct mp_second_impl
  117. {
  118. // An error "no type named 'type'" here means that the argument to mp_second
  119. // is either not a list, or has fewer than two elements
  120. };
  121. template<template<class...> class L, class T1, class T2, class... T> struct mp_second_impl<L<T1, T2, T...>>
  122. {
  123. using type = T2;
  124. };
  125. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  126. template<template<auto...> class L, auto A1, auto A2, auto... A> struct mp_second_impl<L<A1, A2, A...>>
  127. {
  128. using type = mp_value<A2>;
  129. };
  130. #endif
  131. } // namespace detail
  132. template<class L> using mp_second = typename detail::mp_second_impl<L>::type;
  133. // mp_third<L>
  134. namespace detail
  135. {
  136. template<class L> struct mp_third_impl
  137. {
  138. // An error "no type named 'type'" here means that the argument to mp_third
  139. // is either not a list, or has fewer than three elements
  140. };
  141. template<template<class...> class L, class T1, class T2, class T3, class... T> struct mp_third_impl<L<T1, T2, T3, T...>>
  142. {
  143. using type = T3;
  144. };
  145. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  146. template<template<auto...> class L, auto A1, auto A2, auto A3, auto... A> struct mp_third_impl<L<A1, A2, A3, A...>>
  147. {
  148. using type = mp_value<A3>;
  149. };
  150. #endif
  151. } // namespace detail
  152. template<class L> using mp_third = typename detail::mp_third_impl<L>::type;
  153. // mp_push_front<L, T...>
  154. namespace detail
  155. {
  156. template<class L, class... T> struct mp_push_front_impl
  157. {
  158. // An error "no type named 'type'" here means that the first argument to mp_push_front is not a list
  159. };
  160. template<template<class...> class L, class... U, class... T> struct mp_push_front_impl<L<U...>, T...>
  161. {
  162. using type = L<T..., U...>;
  163. };
  164. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  165. template<template<auto...> class L, auto... A, class... T> struct mp_push_front_impl<L<A...>, T...>
  166. {
  167. using type = L<T::value..., A...>;
  168. };
  169. #endif
  170. } // namespace detail
  171. template<class L, class... T> using mp_push_front = typename detail::mp_push_front_impl<L, T...>::type;
  172. // mp_push_back<L, T...>
  173. namespace detail
  174. {
  175. template<class L, class... T> struct mp_push_back_impl
  176. {
  177. // An error "no type named 'type'" here means that the first argument to mp_push_back is not a list
  178. };
  179. template<template<class...> class L, class... U, class... T> struct mp_push_back_impl<L<U...>, T...>
  180. {
  181. using type = L<U..., T...>;
  182. };
  183. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  184. template<template<auto...> class L, auto... A, class... T> struct mp_push_back_impl<L<A...>, T...>
  185. {
  186. using type = L<A..., T::value...>;
  187. };
  188. #endif
  189. } // namespace detail
  190. template<class L, class... T> using mp_push_back = typename detail::mp_push_back_impl<L, T...>::type;
  191. // mp_rename<L, B>
  192. // mp_apply<F, L>
  193. // mp_apply_q<Q, L>
  194. // in detail/mp_rename.hpp
  195. // mp_rename_v<L, B>
  196. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  197. namespace detail
  198. {
  199. template<class L, template<auto...> class B> struct mp_rename_v_impl
  200. {
  201. // An error "no type named 'type'" here means that the first argument to mp_rename_v is not a list
  202. };
  203. template<template<class...> class L, class... T, template<auto...> class B> struct mp_rename_v_impl<L<T...>, B>
  204. {
  205. using type = B<T::value...>;
  206. };
  207. template<template<auto...> class L, auto... A, template<auto...> class B> struct mp_rename_v_impl<L<A...>, B>
  208. {
  209. using type = B<A...>;
  210. };
  211. } // namespace detail
  212. template<class L, template<auto...> class B> using mp_rename_v = typename detail::mp_rename_v_impl<L, B>::type;
  213. #endif
  214. // mp_replace_front<L, T>
  215. namespace detail
  216. {
  217. template<class L, class T> struct mp_replace_front_impl
  218. {
  219. // An error "no type named 'type'" here means that the first argument to mp_replace_front
  220. // is either not a list, or is an empty list
  221. };
  222. template<template<class...> class L, class U1, class... U, class T> struct mp_replace_front_impl<L<U1, U...>, T>
  223. {
  224. using type = L<T, U...>;
  225. };
  226. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  227. template<template<auto...> class L, auto A1, auto... A, class T> struct mp_replace_front_impl<L<A1, A...>, T>
  228. {
  229. using type = L<T::value, A...>;
  230. };
  231. #endif
  232. } // namespace detail
  233. template<class L, class T> using mp_replace_front = typename detail::mp_replace_front_impl<L, T>::type;
  234. // mp_replace_first<L, T>
  235. template<class L, class T> using mp_replace_first = typename detail::mp_replace_front_impl<L, T>::type;
  236. // mp_replace_second<L, T>
  237. namespace detail
  238. {
  239. template<class L, class T> struct mp_replace_second_impl
  240. {
  241. // An error "no type named 'type'" here means that the first argument to mp_replace_second
  242. // is either not a list, or has fewer than two elements
  243. };
  244. template<template<class...> class L, class U1, class U2, class... U, class T> struct mp_replace_second_impl<L<U1, U2, U...>, T>
  245. {
  246. using type = L<U1, T, U...>;
  247. };
  248. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  249. template<template<auto...> class L, auto A1, auto A2, auto... A, class T> struct mp_replace_second_impl<L<A1, A2, A...>, T>
  250. {
  251. using type = L<A1, T::value, A...>;
  252. };
  253. #endif
  254. } // namespace detail
  255. template<class L, class T> using mp_replace_second = typename detail::mp_replace_second_impl<L, T>::type;
  256. // mp_replace_third<L, T>
  257. namespace detail
  258. {
  259. template<class L, class T> struct mp_replace_third_impl
  260. {
  261. // An error "no type named 'type'" here means that the first argument to mp_replace_third
  262. // is either not a list, or has fewer than three elements
  263. };
  264. template<template<class...> class L, class U1, class U2, class U3, class... U, class T> struct mp_replace_third_impl<L<U1, U2, U3, U...>, T>
  265. {
  266. using type = L<U1, U2, T, U...>;
  267. };
  268. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  269. template<template<auto...> class L, auto A1, auto A2, auto A3, auto... A, class T> struct mp_replace_third_impl<L<A1, A2, A3, A...>, T>
  270. {
  271. using type = L<A1, A2, T::value, A...>;
  272. };
  273. #endif
  274. } // namespace detail
  275. template<class L, class T> using mp_replace_third = typename detail::mp_replace_third_impl<L, T>::type;
  276. // mp_transform_front<L, F>
  277. namespace detail
  278. {
  279. template<class L, template<class...> class F> struct mp_transform_front_impl
  280. {
  281. // An error "no type named 'type'" here means that the first argument to mp_transform_front
  282. // is either not a list, or is an empty list
  283. };
  284. template<template<class...> class L, class U1, class... U, template<class...> class F> struct mp_transform_front_impl<L<U1, U...>, F>
  285. {
  286. using type = L<F<U1>, U...>;
  287. };
  288. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  289. template<template<auto...> class L, auto A1, auto... A, template<class...> class F> struct mp_transform_front_impl<L<A1, A...>, F>
  290. {
  291. using type = L<F<mp_value<A1>>::value, A...>;
  292. };
  293. #endif
  294. } // namespace detail
  295. template<class L, template<class...> class F> using mp_transform_front = typename detail::mp_transform_front_impl<L, F>::type;
  296. template<class L, class Q> using mp_transform_front_q = mp_transform_front<L, Q::template fn>;
  297. // mp_transform_first<L, F>
  298. template<class L, template<class...> class F> using mp_transform_first = typename detail::mp_transform_front_impl<L, F>::type;
  299. template<class L, class Q> using mp_transform_first_q = mp_transform_first<L, Q::template fn>;
  300. // mp_transform_second<L, F>
  301. namespace detail
  302. {
  303. template<class L, template<class...> class F> struct mp_transform_second_impl
  304. {
  305. // An error "no type named 'type'" here means that the first argument to mp_transform_second
  306. // is either not a list, or has fewer than two elements
  307. };
  308. template<template<class...> class L, class U1, class U2, class... U, template<class...> class F> struct mp_transform_second_impl<L<U1, U2, U...>, F>
  309. {
  310. using type = L<U1, F<U2>, U...>;
  311. };
  312. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  313. template<template<auto...> class L, auto A1, auto A2, auto... A, template<class...> class F> struct mp_transform_second_impl<L<A1, A2, A...>, F>
  314. {
  315. using type = L<A1, F<mp_value<A2>>::value, A...>;
  316. };
  317. #endif
  318. } // namespace detail
  319. template<class L, template<class...> class F> using mp_transform_second = typename detail::mp_transform_second_impl<L, F>::type;
  320. template<class L, class Q> using mp_transform_second_q = mp_transform_second<L, Q::template fn>;
  321. // mp_transform_third<L, F>
  322. namespace detail
  323. {
  324. template<class L, template<class...> class F> struct mp_transform_third_impl
  325. {
  326. // An error "no type named 'type'" here means that the first argument to mp_transform_third
  327. // is either not a list, or has fewer than three elements
  328. };
  329. template<template<class...> class L, class U1, class U2, class U3, class... U, template<class...> class F> struct mp_transform_third_impl<L<U1, U2, U3, U...>, F>
  330. {
  331. using type = L<U1, U2, F<U3>, U...>;
  332. };
  333. #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
  334. template<template<auto...> class L, auto A1, auto A2, auto A3, auto... A, template<class...> class F> struct mp_transform_third_impl<L<A1, A2, A3, A...>, F>
  335. {
  336. using type = L<A1, A2, F<mp_value<A3>>::value, A...>;
  337. };
  338. #endif
  339. } // namespace detail
  340. template<class L, template<class...> class F> using mp_transform_third = typename detail::mp_transform_third_impl<L, F>::type;
  341. template<class L, class Q> using mp_transform_third_q = mp_transform_third<L, Q::template fn>;
  342. } // namespace mp11
  343. } // namespace boost
  344. #if defined(_MSC_VER) || defined(__GNUC__)
  345. # pragma pop_macro( "I" )
  346. #endif
  347. #endif // #ifndef BOOST_MP11_LIST_HPP_INCLUDED