File indexing completed on 2025-04-26 08:26:31
0001 #ifndef BOOST_COMPAT_INTEGER_SEQUENCE_HPP_INCLUDED
0002 #define BOOST_COMPAT_INTEGER_SEQUENCE_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <cstddef>
0012
0013 #if defined(_MSC_VER) || defined(__GNUC__)
0014 # pragma push_macro( "I" )
0015 # undef I
0016 #endif
0017
0018 #if defined(__has_builtin)
0019 # if __has_builtin(__make_integer_seq)
0020 # define BOOST_COMPAT_HAS_MAKE_INTEGER_SEQ
0021 # endif
0022 #endif
0023
0024 namespace boost
0025 {
0026 namespace compat
0027 {
0028
0029
0030 template<class T, T... I> struct integer_sequence
0031 {
0032 };
0033
0034 #if defined(BOOST_COMPAT_HAS_MAKE_INTEGER_SEQ)
0035
0036 template<class T, T N> using make_integer_sequence = __make_integer_seq<integer_sequence, T, N>;
0037
0038 #else
0039
0040
0041 namespace detail
0042 {
0043
0044
0045 template<bool C, class T, class E> struct iseq_if_c_impl;
0046
0047 template<class T, class E> struct iseq_if_c_impl<true, T, E>
0048 {
0049 using type = T;
0050 };
0051
0052 template<class T, class E> struct iseq_if_c_impl<false, T, E>
0053 {
0054 using type = E;
0055 };
0056
0057 template<bool C, class T, class E> using iseq_if_c = typename iseq_if_c_impl<C, T, E>::type;
0058
0059
0060 template<class T> struct iseq_identity
0061 {
0062 using type = T;
0063 };
0064
0065 template<class S1, class S2> struct append_integer_sequence;
0066
0067 template<class T, T... I, T... J> struct append_integer_sequence<integer_sequence<T, I...>, integer_sequence<T, J...>>
0068 {
0069 using type = integer_sequence< T, I..., ( J + sizeof...(I) )... >;
0070 };
0071
0072 template<class T, T N> struct make_integer_sequence_impl;
0073
0074 template<class T, T N> struct make_integer_sequence_impl_
0075 {
0076 private:
0077
0078 static_assert( N >= 0, "make_integer_sequence<T, N>: N must not be negative" );
0079
0080 static T const M = N / 2;
0081 static T const R = N % 2;
0082
0083 using S1 = typename make_integer_sequence_impl<T, M>::type;
0084 using S2 = typename append_integer_sequence<S1, S1>::type;
0085 using S3 = typename make_integer_sequence_impl<T, R>::type;
0086 using S4 = typename append_integer_sequence<S2, S3>::type;
0087
0088 public:
0089
0090 using type = S4;
0091 };
0092
0093 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> > >
0094 {
0095 };
0096
0097 }
0098
0099
0100 template<class T, T N> using make_integer_sequence = typename detail::make_integer_sequence_impl<T, N>::type;
0101
0102 #endif
0103
0104
0105 template<std::size_t... I> using index_sequence = integer_sequence<std::size_t, I...>;
0106
0107
0108 template<std::size_t N> using make_index_sequence = make_integer_sequence<std::size_t, N>;
0109
0110
0111 template<class... T> using index_sequence_for = make_integer_sequence<std::size_t, sizeof...(T)>;
0112
0113 }
0114 }
0115
0116 #if defined(_MSC_VER) || defined(__GNUC__)
0117 # pragma pop_macro( "I" )
0118 #endif
0119
0120 #endif