1 #ifndef BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED
2 #define BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED
4 // Copyright 2015, 2017, 2019 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/version.hpp>
14 #if defined(__has_builtin)
15 # if __has_builtin(__make_integer_seq)
16 # define BOOST_MP11_HAS_MAKE_INTEGER_SEQ
26 template<class T, T... I> struct integer_sequence
30 #if defined(BOOST_MP11_HAS_MAKE_INTEGER_SEQ)
32 template<class T, T N> using make_integer_sequence = __make_integer_seq<integer_sequence, T, N>;
36 // detail::make_integer_sequence_impl
41 template<bool C, class T, class E> struct iseq_if_c_impl;
43 template<class T, class E> struct iseq_if_c_impl<true, T, E>
48 template<class T, class E> struct iseq_if_c_impl<false, T, E>
53 template<bool C, class T, class E> using iseq_if_c = typename iseq_if_c_impl<C, T, E>::type;
56 template<class T> struct iseq_identity
61 template<class S1, class S2> struct append_integer_sequence;
63 template<class T, T... I, T... J> struct append_integer_sequence<integer_sequence<T, I...>, integer_sequence<T, J...>>
65 using type = integer_sequence< T, I..., ( J + sizeof...(I) )... >;
68 template<class T, T N> struct make_integer_sequence_impl;
70 template<class T, T N> struct make_integer_sequence_impl_
74 static_assert( N >= 0, "make_integer_sequence<T, N>: N must not be negative" );
76 static T const M = N / 2;
77 static T const R = N % 2;
79 using S1 = typename make_integer_sequence_impl<T, M>::type;
80 using S2 = typename append_integer_sequence<S1, S1>::type;
81 using S3 = typename make_integer_sequence_impl<T, R>::type;
82 using S4 = typename append_integer_sequence<S2, S3>::type;
89 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> > >
95 // make_integer_sequence
96 template<class T, T N> using make_integer_sequence = typename detail::make_integer_sequence_impl<T, N>::type;
98 #endif // defined(BOOST_MP11_HAS_MAKE_INTEGER_SEQ)
101 template<std::size_t... I> using index_sequence = integer_sequence<std::size_t, I...>;
103 // make_index_sequence
104 template<std::size_t N> using make_index_sequence = make_integer_sequence<std::size_t, N>;
106 // index_sequence_for
107 template<class... T> using index_sequence_for = make_integer_sequence<std::size_t, sizeof...(T)>;
112 #endif // #ifndef BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED