123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- #ifndef BOOST_LEAF_DETAIL_MP11_HPP_INCLUDED
- #define BOOST_LEAF_DETAIL_MP11_HPP_INCLUDED
- // Copyright 2015-2017 Peter Dimov.
- // Copyright 2019 Emil Dotchevski.
- //
- // Distributed under the Boost Software License, Version 1.0.
- //
- // See accompanying file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt
- #include <type_traits>
- #include <cstddef>
- namespace boost { namespace leaf { namespace leaf_detail_mp11 {
- // mp_list<T...>
- template<class... T> struct mp_list
- {
- };
- // mp_identity
- template<class T> struct mp_identity
- {
- using type = T;
- };
- // mp_inherit
- template<class... T> struct mp_inherit: T... {};
- // mp_if, mp_if_c
- namespace detail
- {
- template<bool C, class T, class... E> struct mp_if_c_impl
- {
- };
- template<class T, class... E> struct mp_if_c_impl<true, T, E...>
- {
- using type = T;
- };
- template<class T, class E> struct mp_if_c_impl<false, T, E>
- {
- using type = E;
- };
- } // namespace detail
- template<bool C, class T, class... E> using mp_if_c = typename detail::mp_if_c_impl<C, T, E...>::type;
- template<class C, class T, class... E> using mp_if = typename detail::mp_if_c_impl<static_cast<bool>(C::value), T, E...>::type;
- // mp_bool
- template<bool B> using mp_bool = std::integral_constant<bool, B>;
- using mp_true = mp_bool<true>;
- using mp_false = mp_bool<false>;
- // mp_to_bool
- template<class T> using mp_to_bool = mp_bool<static_cast<bool>( T::value )>;
- // mp_not<T>
- template<class T> using mp_not = mp_bool< !T::value >;
- // mp_int
- template<int I> using mp_int = std::integral_constant<int, I>;
- // mp_size_t
- template<std::size_t N> using mp_size_t = std::integral_constant<std::size_t, N>;
- // mp_set_contains<S, V>
- namespace detail
- {
- template<class S, class V> struct mp_set_contains_impl;
- template<template<class...> class L, class... T, class V> struct mp_set_contains_impl<L<T...>, V>
- {
- using type = mp_to_bool<std::is_base_of<mp_identity<V>, mp_inherit<mp_identity<T>...> > >;
- };
- } // namespace detail
- template<class S, class V> using mp_set_contains = typename detail::mp_set_contains_impl<S, V>::type;
- // mp_set_push_back<S, T...>
- namespace detail
- {
- template<class S, class... T> struct mp_set_push_back_impl;
- template<template<class...> class L, class... U> struct mp_set_push_back_impl<L<U...>>
- {
- using type = L<U...>;
- };
- template<template<class...> class L, class... U, class T1, class... T> struct mp_set_push_back_impl<L<U...>, T1, T...>
- {
- using S = mp_if<mp_set_contains<L<U...>, T1>, L<U...>, L<U..., T1>>;
- using type = typename mp_set_push_back_impl<S, T...>::type;
- };
- } // namespace detail
- template<class S, class... T> using mp_set_push_back = typename detail::mp_set_push_back_impl<S, T...>::type;
- // mp_unique<L>
- namespace detail
- {
- template<class L> struct mp_unique_impl;
- template<template<class...> class L, class... T> struct mp_unique_impl<L<T...>>
- {
- using type = mp_set_push_back<L<>, T...>;
- };
- } // namespace detail
- template<class L> using mp_unique = typename detail::mp_unique_impl<L>::type;
- // mp_append<L...>
- namespace detail
- {
- template<class... L> struct mp_append_impl;
- template<> struct mp_append_impl<>
- {
- using type = mp_list<>;
- };
- template<template<class...> class L, class... T> struct mp_append_impl<L<T...>>
- {
- using type = L<T...>;
- };
- template<template<class...> class L1, class... T1, template<class...> class L2, class... T2, class... Lr> struct mp_append_impl<L1<T1...>, L2<T2...>, Lr...>
- {
- using type = typename mp_append_impl<L1<T1..., T2...>, Lr...>::type;
- };
- }
- template<class... L> using mp_append = typename detail::mp_append_impl<L...>::type;
- // mp_front<L>
- namespace detail
- {
- template<class L> struct mp_front_impl
- {
- // An error "no type named 'type'" here means that the argument to mp_front
- // is either not a list, or is an empty list
- };
- template<template<class...> class L, class T1, class... T> struct mp_front_impl<L<T1, T...>>
- {
- using type = T1;
- };
- } // namespace detail
- template<class L> using mp_front = typename detail::mp_front_impl<L>::type;
- // mp_pop_front<L>
- namespace detail
- {
- template<class L> struct mp_pop_front_impl
- {
- // An error "no type named 'type'" here means that the argument to mp_pop_front
- // is either not a list, or is an empty list
- };
- template<template<class...> class L, class T1, class... T> struct mp_pop_front_impl<L<T1, T...>>
- {
- using type = L<T...>;
- };
- } // namespace detail
- template<class L> using mp_pop_front = typename detail::mp_pop_front_impl<L>::type;
- // mp_first<L>
- template<class L> using mp_first = mp_front<L>;
- // mp_rest<L>
- template<class L> using mp_rest = mp_pop_front<L>;
- // mp_remove_if<L, P>
- namespace detail
- {
- template<class L, template<class...> class P> struct mp_remove_if_impl;
- template<template<class...> class L, class... T, template<class...> class P> struct mp_remove_if_impl<L<T...>, P>
- {
- template<class U> using _f = mp_if<P<U>, mp_list<>, mp_list<U>>;
- using type = mp_append<L<>, _f<T>...>;
- };
- } // namespace detail
- template<class L, template<class...> class P> using mp_remove_if = typename detail::mp_remove_if_impl<L, P>::type;
- // integer_sequence
- template<class T, T... I> struct integer_sequence
- {
- };
- // detail::make_integer_sequence_impl
- namespace detail
- {
- // iseq_if_c
- template<bool C, class T, class E> struct iseq_if_c_impl;
- template<class T, class E> struct iseq_if_c_impl<true, T, E>
- {
- using type = T;
- };
- template<class T, class E> struct iseq_if_c_impl<false, T, E>
- {
- using type = E;
- };
- template<bool C, class T, class E> using iseq_if_c = typename iseq_if_c_impl<C, T, E>::type;
- // iseq_identity
- template<class T> struct iseq_identity
- {
- using type = T;
- };
- template<class S1, class S2> struct append_integer_sequence;
- template<class T, T... I, T... J> struct append_integer_sequence<integer_sequence<T, I...>, integer_sequence<T, J...>>
- {
- using type = integer_sequence< T, I..., ( J + sizeof...(I) )... >;
- };
- template<class T, T N> struct make_integer_sequence_impl;
- template<class T, T N> struct make_integer_sequence_impl_
- {
- private:
- static_assert( N >= 0, "make_integer_sequence<T, N>: N must not be negative" );
- static T const M = N / 2;
- static T const R = N % 2;
- using S1 = typename make_integer_sequence_impl<T, M>::type;
- using S2 = typename append_integer_sequence<S1, S1>::type;
- using S3 = typename make_integer_sequence_impl<T, R>::type;
- using S4 = typename append_integer_sequence<S2, S3>::type;
- public:
- using type = S4;
- };
- 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> > >
- {
- };
- } // namespace detail
- // make_integer_sequence
- template<class T, T N> using make_integer_sequence = typename detail::make_integer_sequence_impl<T, N>::type;
- // index_sequence
- template<std::size_t... I> using index_sequence = integer_sequence<std::size_t, I...>;
- // make_index_sequence
- template<std::size_t N> using make_index_sequence = make_integer_sequence<std::size_t, N>;
- // index_sequence_for
- template<class... T> using index_sequence_for = make_integer_sequence<std::size_t, sizeof...(T)>;
- // implementation by Bruno Dutra (by the name is_evaluable)
- namespace detail
- {
- template<template<class...> class F, class... T> struct mp_valid_impl
- {
- template<template<class...> class G, class = G<T...>> static mp_true check(int);
- template<template<class...> class> static mp_false check(...);
- using type = decltype(check<F>(0));
- };
- } // namespace detail
- template<template<class...> class F, class... T> using mp_valid = typename detail::mp_valid_impl<F, T...>::type;
- } } }
- #endif
|