1 #ifndef BOOST_MP11_LIST_HPP_INCLUDED
2 #define BOOST_MP11_LIST_HPP_INCLUDED
4 // Copyright 2015-2017 Peter Dimov.
6 // Distributed under the Boost Software License, Version 1.0.
8 // See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt
11 #include <boost/mp11/integral.hpp>
12 #include <boost/mp11/detail/mp_list.hpp>
13 #include <boost/mp11/detail/mp_is_list.hpp>
14 #include <boost/mp11/detail/mp_append.hpp>
15 #include <boost/mp11/detail/config.hpp>
16 #include <type_traits>
24 template<class T, T... I> using mp_list_c = mp_list<std::integral_constant<T, I>...>;
27 // in detail/mp_is_list.hpp
33 template<class L> struct mp_size_impl
35 // An error "no type named 'type'" here means that the argument to mp_size is not a list
38 template<template<class...> class L, class... T> struct mp_size_impl<L<T...>>
40 using type = mp_size_t<sizeof...(T)>;
45 template<class L> using mp_size = typename detail::mp_size_impl<L>::type;
48 template<class L> using mp_empty = mp_bool< mp_size<L>::value == 0 >;
54 template<class L1, class L2> struct mp_assign_impl;
56 template<template<class...> class L1, class... T, template<class...> class L2, class... U> struct mp_assign_impl<L1<T...>, L2<U...>>
58 using type = L1<U...>;
63 template<class L1, class L2> using mp_assign = typename detail::mp_assign_impl<L1, L2>::type;
66 template<class L> using mp_clear = mp_assign<L, mp_list<>>;
72 template<class L> struct mp_front_impl
74 // An error "no type named 'type'" here means that the argument to mp_front
75 // is either not a list, or is an empty list
78 template<template<class...> class L, class T1, class... T> struct mp_front_impl<L<T1, T...>>
85 template<class L> using mp_front = typename detail::mp_front_impl<L>::type;
91 template<class L> struct mp_pop_front_impl
93 // An error "no type named 'type'" here means that the argument to mp_pop_front
94 // is either not a list, or is an empty list
97 template<template<class...> class L, class T1, class... T> struct mp_pop_front_impl<L<T1, T...>>
102 } // namespace detail
104 template<class L> using mp_pop_front = typename detail::mp_pop_front_impl<L>::type;
107 template<class L> using mp_first = mp_front<L>;
110 template<class L> using mp_rest = mp_pop_front<L>;
116 template<class L> struct mp_second_impl
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
122 template<template<class...> class L, class T1, class T2, class... T> struct mp_second_impl<L<T1, T2, T...>>
127 } // namespace detail
129 template<class L> using mp_second = typename detail::mp_second_impl<L>::type;
135 template<class L> struct mp_third_impl
137 // An error "no type named 'type'" here means that the argument to mp_third
138 // is either not a list, or has fewer than three elements
141 template<template<class...> class L, class T1, class T2, class T3, class... T> struct mp_third_impl<L<T1, T2, T3, T...>>
146 } // namespace detail
148 template<class L> using mp_third = typename detail::mp_third_impl<L>::type;
150 // mp_push_front<L, T...>
154 template<class L, class... T> struct mp_push_front_impl
156 // An error "no type named 'type'" here means that the first argument to mp_push_front is not a list
159 template<template<class...> class L, class... U, class... T> struct mp_push_front_impl<L<U...>, T...>
161 using type = L<T..., U...>;
164 } // namespace detail
166 template<class L, class... T> using mp_push_front = typename detail::mp_push_front_impl<L, T...>::type;
168 // mp_push_back<L, T...>
172 template<class L, class... T> struct mp_push_back_impl
174 // An error "no type named 'type'" here means that the first argument to mp_push_back is not a list
177 template<template<class...> class L, class... U, class... T> struct mp_push_back_impl<L<U...>, T...>
179 using type = L<U..., T...>;
182 } // namespace detail
184 template<class L, class... T> using mp_push_back = typename detail::mp_push_back_impl<L, T...>::type;
190 template<class A, template<class...> class B> struct mp_rename_impl
192 // An error "no type named 'type'" here means that the first argument to mp_rename is not a list
195 template<template<class...> class A, class... T, template<class...> class B> struct mp_rename_impl<A<T...>, B>
197 using type = B<T...>;
200 } // namespace detail
202 template<class A, template<class...> class B> using mp_rename = typename detail::mp_rename_impl<A, B>::type;
204 template<template<class...> class F, class L> using mp_apply = typename detail::mp_rename_impl<L, F>::type;
206 template<class Q, class L> using mp_apply_q = typename detail::mp_rename_impl<L, Q::template fn>::type;
208 // mp_replace_front<L, T>
212 template<class L, class T> struct mp_replace_front_impl
214 // An error "no type named 'type'" here means that the first argument to mp_replace_front
215 // is either not a list, or is an empty list
218 template<template<class...> class L, class U1, class... U, class T> struct mp_replace_front_impl<L<U1, U...>, T>
220 using type = L<T, U...>;
223 } // namespace detail
225 template<class L, class T> using mp_replace_front = typename detail::mp_replace_front_impl<L, T>::type;
227 // mp_replace_first<L, T>
228 template<class L, class T> using mp_replace_first = typename detail::mp_replace_front_impl<L, T>::type;
230 // mp_replace_second<L, T>
234 template<class L, class T> struct mp_replace_second_impl
236 // An error "no type named 'type'" here means that the first argument to mp_replace_second
237 // is either not a list, or has fewer than two elements
240 template<template<class...> class L, class U1, class U2, class... U, class T> struct mp_replace_second_impl<L<U1, U2, U...>, T>
242 using type = L<U1, T, U...>;
245 } // namespace detail
247 template<class L, class T> using mp_replace_second = typename detail::mp_replace_second_impl<L, T>::type;
249 // mp_replace_third<L, T>
253 template<class L, class T> struct mp_replace_third_impl
255 // An error "no type named 'type'" here means that the first argument to mp_replace_third
256 // is either not a list, or has fewer than three elements
259 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>
261 using type = L<U1, U2, T, U...>;
264 } // namespace detail
266 template<class L, class T> using mp_replace_third = typename detail::mp_replace_third_impl<L, T>::type;
268 // mp_transform_front<L, F>
272 template<class L, template<class...> class F> struct mp_transform_front_impl
274 // An error "no type named 'type'" here means that the first argument to mp_transform_front
275 // is either not a list, or is an empty list
278 template<template<class...> class L, class U1, class... U, template<class...> class F> struct mp_transform_front_impl<L<U1, U...>, F>
280 using type = L<F<U1>, U...>;
283 } // namespace detail
285 template<class L, template<class...> class F> using mp_transform_front = typename detail::mp_transform_front_impl<L, F>::type;
286 template<class L, class Q> using mp_transform_front_q = mp_transform_front<L, Q::template fn>;
288 // mp_transform_first<L, F>
289 template<class L, template<class...> class F> using mp_transform_first = typename detail::mp_transform_front_impl<L, F>::type;
290 template<class L, class Q> using mp_transform_first_q = mp_transform_first<L, Q::template fn>;
292 // mp_transform_second<L, F>
296 template<class L, template<class...> class F> struct mp_transform_second_impl
298 // An error "no type named 'type'" here means that the first argument to mp_transform_second
299 // is either not a list, or has fewer than two elements
302 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>
304 using type = L<U1, F<U2>, U...>;
307 } // namespace detail
309 template<class L, template<class...> class F> using mp_transform_second = typename detail::mp_transform_second_impl<L, F>::type;
310 template<class L, class Q> using mp_transform_second_q = mp_transform_second<L, Q::template fn>;
312 // mp_transform_third<L, F>
316 template<class L, template<class...> class F> struct mp_transform_third_impl
318 // An error "no type named 'type'" here means that the first argument to mp_transform_third
319 // is either not a list, or has fewer than three elements
322 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>
324 using type = L<U1, U2, F<U3>, U...>;
327 } // namespace detail
329 template<class L, template<class...> class F> using mp_transform_third = typename detail::mp_transform_third_impl<L, F>::type;
330 template<class L, class Q> using mp_transform_third_q = mp_transform_third<L, Q::template fn>;
335 #endif // #ifndef BOOST_MP11_LIST_HPP_INCLUDED