File indexing completed on 2025-01-18 09:39:11
0001 #ifndef BOOST_LEAF_DETAIL_MP11_HPP_INCLUDED
0002 #define BOOST_LEAF_DETAIL_MP11_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <type_traits>
0013 #include <cstddef>
0014
0015 namespace boost { namespace leaf { namespace leaf_detail_mp11 {
0016
0017
0018 template<class... T> struct mp_list
0019 {
0020 };
0021
0022
0023 template<class T> struct mp_identity
0024 {
0025 using type = T;
0026 };
0027
0028
0029 template<class... T> struct mp_inherit: T... {};
0030
0031
0032 namespace detail
0033 {
0034
0035 template<bool C, class T, class... E> struct mp_if_c_impl
0036 {
0037 };
0038
0039 template<class T, class... E> struct mp_if_c_impl<true, T, E...>
0040 {
0041 using type = T;
0042 };
0043
0044 template<class T, class E> struct mp_if_c_impl<false, T, E>
0045 {
0046 using type = E;
0047 };
0048
0049 }
0050
0051 template<bool C, class T, class... E> using mp_if_c = typename detail::mp_if_c_impl<C, T, E...>::type;
0052 template<class C, class T, class... E> using mp_if = typename detail::mp_if_c_impl<static_cast<bool>(C::value), T, E...>::type;
0053
0054
0055 template<bool B> using mp_bool = std::integral_constant<bool, B>;
0056
0057 using mp_true = mp_bool<true>;
0058 using mp_false = mp_bool<false>;
0059
0060
0061 template<class T> using mp_to_bool = mp_bool<static_cast<bool>( T::value )>;
0062
0063
0064 template<class T> using mp_not = mp_bool< !T::value >;
0065
0066
0067 template<int I> using mp_int = std::integral_constant<int, I>;
0068
0069
0070 template<std::size_t N> using mp_size_t = std::integral_constant<std::size_t, N>;
0071
0072
0073 namespace detail
0074 {
0075
0076 template<class S, class V> struct mp_set_contains_impl;
0077
0078 template<template<class...> class L, class... T, class V> struct mp_set_contains_impl<L<T...>, V>
0079 {
0080 using type = mp_to_bool<std::is_base_of<mp_identity<V>, mp_inherit<mp_identity<T>...> > >;
0081 };
0082
0083 }
0084
0085 template<class S, class V> using mp_set_contains = typename detail::mp_set_contains_impl<S, V>::type;
0086
0087
0088 namespace detail
0089 {
0090
0091 template<class S, class... T> struct mp_set_push_back_impl;
0092
0093 template<template<class...> class L, class... U> struct mp_set_push_back_impl<L<U...>>
0094 {
0095 using type = L<U...>;
0096 };
0097
0098 template<template<class...> class L, class... U, class T1, class... T> struct mp_set_push_back_impl<L<U...>, T1, T...>
0099 {
0100 using S = mp_if<mp_set_contains<L<U...>, T1>, L<U...>, L<U..., T1>>;
0101 using type = typename mp_set_push_back_impl<S, T...>::type;
0102 };
0103
0104 }
0105
0106 template<class S, class... T> using mp_set_push_back = typename detail::mp_set_push_back_impl<S, T...>::type;
0107
0108
0109 namespace detail
0110 {
0111
0112 template<class L> struct mp_unique_impl;
0113
0114 template<template<class...> class L, class... T> struct mp_unique_impl<L<T...>>
0115 {
0116 using type = mp_set_push_back<L<>, T...>;
0117 };
0118
0119 }
0120
0121 template<class L> using mp_unique = typename detail::mp_unique_impl<L>::type;
0122
0123
0124
0125 namespace detail
0126 {
0127
0128 template<class... L> struct mp_append_impl;
0129
0130 template<> struct mp_append_impl<>
0131 {
0132 using type = mp_list<>;
0133 };
0134
0135 template<template<class...> class L, class... T> struct mp_append_impl<L<T...>>
0136 {
0137 using type = L<T...>;
0138 };
0139
0140 template<template<class...> class L1, class... T1, template<class...> class L2, class... T2, class... Lr> struct mp_append_impl<L1<T1...>, L2<T2...>, Lr...>
0141 {
0142 using type = typename mp_append_impl<L1<T1..., T2...>, Lr...>::type;
0143 };
0144
0145 }
0146
0147 template<class... L> using mp_append = typename detail::mp_append_impl<L...>::type;
0148
0149
0150 namespace detail
0151 {
0152
0153 template<class L> struct mp_front_impl
0154 {
0155
0156
0157 };
0158
0159 template<template<class...> class L, class T1, class... T> struct mp_front_impl<L<T1, T...>>
0160 {
0161 using type = T1;
0162 };
0163
0164 }
0165
0166 template<class L> using mp_front = typename detail::mp_front_impl<L>::type;
0167
0168
0169 namespace detail
0170 {
0171
0172 template<class L> struct mp_pop_front_impl
0173 {
0174
0175
0176 };
0177
0178 template<template<class...> class L, class T1, class... T> struct mp_pop_front_impl<L<T1, T...>>
0179 {
0180 using type = L<T...>;
0181 };
0182
0183 }
0184
0185 template<class L> using mp_pop_front = typename detail::mp_pop_front_impl<L>::type;
0186
0187
0188 template<class L> using mp_first = mp_front<L>;
0189
0190
0191 template<class L> using mp_rest = mp_pop_front<L>;
0192
0193
0194 namespace detail
0195 {
0196
0197 template<class L, template<class...> class P> struct mp_remove_if_impl;
0198
0199 template<template<class...> class L, class... T, template<class...> class P> struct mp_remove_if_impl<L<T...>, P>
0200 {
0201 template<class U> using _f = mp_if<P<U>, mp_list<>, mp_list<U>>;
0202 using type = mp_append<L<>, _f<T>...>;
0203 };
0204
0205 }
0206
0207 template<class L, template<class...> class P> using mp_remove_if = typename detail::mp_remove_if_impl<L, P>::type;
0208
0209
0210 template<class T, T... I> struct integer_sequence
0211 {
0212 };
0213
0214
0215 namespace detail
0216 {
0217
0218
0219 template<bool C, class T, class E> struct iseq_if_c_impl;
0220
0221 template<class T, class E> struct iseq_if_c_impl<true, T, E>
0222 {
0223 using type = T;
0224 };
0225
0226 template<class T, class E> struct iseq_if_c_impl<false, T, E>
0227 {
0228 using type = E;
0229 };
0230
0231 template<bool C, class T, class E> using iseq_if_c = typename iseq_if_c_impl<C, T, E>::type;
0232
0233
0234 template<class T> struct iseq_identity
0235 {
0236 using type = T;
0237 };
0238
0239 template<class S1, class S2> struct append_integer_sequence;
0240
0241 template<class T, T... I, T... J> struct append_integer_sequence<integer_sequence<T, I...>, integer_sequence<T, J...>>
0242 {
0243 using type = integer_sequence< T, I..., ( J + sizeof...(I) )... >;
0244 };
0245
0246 template<class T, T N> struct make_integer_sequence_impl;
0247
0248 template<class T, T N> struct make_integer_sequence_impl_
0249 {
0250 private:
0251
0252 static_assert( N >= 0, "make_integer_sequence<T, N>: N must not be negative" );
0253
0254 static T const M = N / 2;
0255 static T const R = N % 2;
0256
0257 using S1 = typename make_integer_sequence_impl<T, M>::type;
0258 using S2 = typename append_integer_sequence<S1, S1>::type;
0259 using S3 = typename make_integer_sequence_impl<T, R>::type;
0260 using S4 = typename append_integer_sequence<S2, S3>::type;
0261
0262 public:
0263
0264 using type = S4;
0265 };
0266
0267 template<class T, T N> struct make_integer_sequence_impl: iseq_if_c<N == 0, iseq_identity<integer_sequence<T>>, iseq_if_c<N == 1, iseq_identity<integer_sequence<T, 0>>, make_integer_sequence_impl_<T, N> > >
0268 {
0269 };
0270
0271 }
0272
0273
0274 template<class T, T N> using make_integer_sequence = typename detail::make_integer_sequence_impl<T, N>::type;
0275
0276
0277 template<std::size_t... I> using index_sequence = integer_sequence<std::size_t, I...>;
0278
0279
0280 template<std::size_t N> using make_index_sequence = make_integer_sequence<std::size_t, N>;
0281
0282
0283 template<class... T> using index_sequence_for = make_integer_sequence<std::size_t, sizeof...(T)>;
0284
0285
0286 namespace detail
0287 {
0288
0289 template<template<class...> class F, class... T> struct mp_valid_impl
0290 {
0291 template<template<class...> class G, class = G<T...>> static mp_true check(int);
0292 template<template<class...> class> static mp_false check(...);
0293
0294 using type = decltype(check<F>(0));
0295 };
0296
0297 }
0298
0299 template<template<class...> class F, class... T> using mp_valid = typename detail::mp_valid_impl<F, T...>::type;
0300
0301 } } }
0302
0303 #endif