]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/mp11/integer_sequence.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / mp11 / integer_sequence.hpp
1 #ifndef BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED
2 #define BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED
3
4 // Copyright 2015, 2017 Peter Dimov.
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 //
8 // See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt
10
11 #include <cstddef>
12
13 namespace boost
14 {
15 namespace mp11
16 {
17
18 // integer_sequence
19 template<class T, T... I> struct integer_sequence
20 {
21 };
22
23 // detail::make_integer_sequence_impl
24 namespace detail
25 {
26
27 // iseq_if_c
28 template<bool C, class T, class E> struct iseq_if_c_impl;
29
30 template<class T, class E> struct iseq_if_c_impl<true, T, E>
31 {
32 using type = T;
33 };
34
35 template<class T, class E> struct iseq_if_c_impl<false, T, E>
36 {
37 using type = E;
38 };
39
40 template<bool C, class T, class E> using iseq_if_c = typename iseq_if_c_impl<C, T, E>::type;
41
42 // iseq_identity
43 template<class T> struct iseq_identity
44 {
45 using type = T;
46 };
47
48 template<class S1, class S2> struct append_integer_sequence;
49
50 template<class T, T... I, T... J> struct append_integer_sequence<integer_sequence<T, I...>, integer_sequence<T, J...>>
51 {
52 using type = integer_sequence< T, I..., ( J + sizeof...(I) )... >;
53 };
54
55 template<class T, T N> struct make_integer_sequence_impl;
56
57 template<class T, T N> struct make_integer_sequence_impl_
58 {
59 private:
60
61 static_assert( N >= 0, "make_integer_sequence<T, N>: N must not be negative" );
62
63 static T const M = N / 2;
64 static T const R = N % 2;
65
66 using S1 = typename make_integer_sequence_impl<T, M>::type;
67 using S2 = typename append_integer_sequence<S1, S1>::type;
68 using S3 = typename make_integer_sequence_impl<T, R>::type;
69 using S4 = typename append_integer_sequence<S2, S3>::type;
70
71 public:
72
73 using type = S4;
74 };
75
76 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>>>
77 {
78 };
79
80 } // namespace detail
81
82 // make_integer_sequence
83 template<class T, T N> using make_integer_sequence = typename detail::make_integer_sequence_impl<T, N>::type;
84
85 // index_sequence
86 template<std::size_t... I> using index_sequence = integer_sequence<std::size_t, I...>;
87
88 // make_index_sequence
89 template<std::size_t N> using make_index_sequence = make_integer_sequence<std::size_t, N>;
90
91 // index_sequence_for
92 template<class... T> using index_sequence_for = make_integer_sequence<std::size_t, sizeof...(T)>;
93
94 } // namespace mp11
95 } // namespace boost
96
97 #endif // #ifndef BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED