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_append.hpp>
14 #include <boost/config.hpp>
15 #include <boost/detail/workaround.hpp>
16 #include <type_traits>
24 template<class T, T... I> using mp_list_c = mp_list<std::integral_constant<T, I>...>;
30 template<class L> struct mp_is_list_impl
32 using type = mp_false;
35 template<template<class...> class L, class... T> struct mp_is_list_impl<L<T...>>
42 template<class L> using mp_is_list = typename detail::mp_is_list_impl<L>::type;
48 template<class L> struct mp_size_impl
50 // An error "no type named 'type'" here means that the argument to mp_size is not a list
53 template<template<class...> class L, class... T> struct mp_size_impl<L<T...>>
55 using type = mp_size_t<sizeof...(T)>;
60 template<class L> using mp_size = typename detail::mp_size_impl<L>::type;
63 template<class L> using mp_empty = mp_bool< mp_size<L>::value == 0 >;
69 template<class L1, class L2> struct mp_assign_impl;
71 template<template<class...> class L1, class... T, template<class...> class L2, class... U> struct mp_assign_impl<L1<T...>, L2<U...>>
73 using type = L1<U...>;
78 template<class L1, class L2> using mp_assign = typename detail::mp_assign_impl<L1, L2>::type;
81 template<class L> using mp_clear = mp_assign<L, mp_list<>>;
87 template<class L> struct mp_front_impl
89 // An error "no type named 'type'" here means that the argument to mp_front
90 // is either not a list, or is an empty list
93 template<template<class...> class L, class T1, class... T> struct mp_front_impl<L<T1, T...>>
100 template<class L> using mp_front = typename detail::mp_front_impl<L>::type;
106 template<class L> struct mp_pop_front_impl
108 // An error "no type named 'type'" here means that the argument to mp_pop_front
109 // is either not a list, or is an empty list
112 template<template<class...> class L, class T1, class... T> struct mp_pop_front_impl<L<T1, T...>>
114 using type = L<T...>;
117 } // namespace detail
119 template<class L> using mp_pop_front = typename detail::mp_pop_front_impl<L>::type;
122 template<class L> using mp_first = mp_front<L>;
125 template<class L> using mp_rest = mp_pop_front<L>;
131 template<class L> struct mp_second_impl
133 // An error "no type named 'type'" here means that the argument to mp_second
134 // is either not a list, or has fewer than two elements
137 template<template<class...> class L, class T1, class T2, class... T> struct mp_second_impl<L<T1, T2, T...>>
142 } // namespace detail
144 template<class L> using mp_second = typename detail::mp_second_impl<L>::type;
150 template<class L> struct mp_third_impl
152 // An error "no type named 'type'" here means that the argument to mp_third
153 // is either not a list, or has fewer than three elements
156 template<template<class...> class L, class T1, class T2, class T3, class... T> struct mp_third_impl<L<T1, T2, T3, T...>>
161 } // namespace detail
163 template<class L> using mp_third = typename detail::mp_third_impl<L>::type;
165 // mp_push_front<L, T...>
169 template<class L, class... T> struct mp_push_front_impl
171 // An error "no type named 'type'" here means that the first argument to mp_push_front is not a list
174 template<template<class...> class L, class... U, class... T> struct mp_push_front_impl<L<U...>, T...>
176 using type = L<T..., U...>;
179 } // namespace detail
181 template<class L, class... T> using mp_push_front = typename detail::mp_push_front_impl<L, T...>::type;
183 // mp_push_back<L, T...>
187 template<class L, class... T> struct mp_push_back_impl
189 // An error "no type named 'type'" here means that the first argument to mp_push_back is not a list
192 template<template<class...> class L, class... U, class... T> struct mp_push_back_impl<L<U...>, T...>
194 using type = L<U..., T...>;
197 } // namespace detail
199 template<class L, class... T> using mp_push_back = typename detail::mp_push_back_impl<L, T...>::type;
205 template<class A, template<class...> class B> struct mp_rename_impl
207 // An error "no type named 'type'" here means that the first argument to mp_rename is not a list
210 template<template<class...> class A, class... T, template<class...> class B> struct mp_rename_impl<A<T...>, B>
212 using type = B<T...>;
215 } // namespace detail
217 template<class A, template<class...> class B> using mp_rename = typename detail::mp_rename_impl<A, B>::type;
219 template<template<class...> class F, class L> using mp_apply = typename detail::mp_rename_impl<L, F>::type;
221 template<class Q, class L> using mp_apply_q = typename detail::mp_rename_impl<L, Q::template fn>::type;
223 // mp_replace_front<L, T>
227 template<class L, class T> struct mp_replace_front_impl
229 // An error "no type named 'type'" here means that the first argument to mp_replace_front
230 // is either not a list, or is an empty list
233 template<template<class...> class L, class U1, class... U, class T> struct mp_replace_front_impl<L<U1, U...>, T>
235 using type = L<T, U...>;
238 } // namespace detail
240 template<class L, class T> using mp_replace_front = typename detail::mp_replace_front_impl<L, T>::type;
242 // mp_replace_first<L, T>
243 template<class L, class T> using mp_replace_first = typename detail::mp_replace_front_impl<L, T>::type;
245 // mp_replace_second<L, T>
249 template<class L, class T> struct mp_replace_second_impl
251 // An error "no type named 'type'" here means that the first argument to mp_replace_second
252 // is either not a list, or has fewer than two elements
255 template<template<class...> class L, class U1, class U2, class... U, class T> struct mp_replace_second_impl<L<U1, U2, U...>, T>
257 using type = L<U1, T, U...>;
260 } // namespace detail
262 template<class L, class T> using mp_replace_second = typename detail::mp_replace_second_impl<L, T>::type;
264 // mp_replace_third<L, T>
268 template<class L, class T> struct mp_replace_third_impl
270 // An error "no type named 'type'" here means that the first argument to mp_replace_third
271 // is either not a list, or has fewer than three elements
274 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>
276 using type = L<U1, U2, T, U...>;
279 } // namespace detail
281 template<class L, class T> using mp_replace_third = typename detail::mp_replace_third_impl<L, T>::type;
286 #endif // #ifndef BOOST_MP11_LIST_HPP_INCLUDED