]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/pfr/detail/make_integer_sequence.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / pfr / detail / make_integer_sequence.hpp
CommitLineData
20effc67 1// Copyright (c) 2018 Sergei Fedorov
1e59de90 2// Copyright (c) 2019-2022 Antony Polukhin
20effc67
TL
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#ifndef BOOST_PFR_DETAIL_MAKE_INTEGER_SEQUENCE_HPP
8#define BOOST_PFR_DETAIL_MAKE_INTEGER_SEQUENCE_HPP
9#pragma once
10
11#include <boost/pfr/detail/config.hpp>
12
13#include <type_traits>
14#include <utility>
15#include <cstddef>
16
17namespace boost { namespace pfr { namespace detail {
18
19#if BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 0
20
21#ifdef __has_builtin
22# if __has_builtin(__make_integer_seq)
23# define BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
24# endif
25#endif
26
27#ifdef BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
28
29using std::integer_sequence;
30
31// Clang unable to use namespace qualified std::integer_sequence in __make_integer_seq.
32template <typename T, T N>
33using make_integer_sequence = __make_integer_seq<integer_sequence, T, N>;
34
35#undef BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
36
37#else
38
39template <typename T, typename U>
40struct join_sequences;
41
42template <typename T, T... A, T... B>
43struct join_sequences<std::integer_sequence<T, A...>, std::integer_sequence<T, B...>> {
44 using type = std::integer_sequence<T, A..., B...>;
45};
46
47template <typename T, T Min, T Max>
48struct build_sequence_impl {
49 static_assert(Min < Max, "Start of range must be less than its end");
50 static constexpr T size = Max - Min;
51 using type = typename join_sequences<
52 typename build_sequence_impl<T, Min, Min + size / 2>::type,
53 typename build_sequence_impl<T, Min + size / 2 + 1, Max>::type
54 >::type;
55};
56
57template <typename T, T V>
58struct build_sequence_impl<T, V, V> {
59 using type = std::integer_sequence<T, V>;
60};
61
62template <typename T, std::size_t N>
63struct make_integer_sequence_impl : build_sequence_impl<T, 0, N - 1> {};
64
65template <typename T>
66struct make_integer_sequence_impl<T, 0> {
67 using type = std::integer_sequence<T>;
68};
69
70template <typename T, T N>
71using make_integer_sequence = typename make_integer_sequence_impl<T, N>::type;
72
73#endif // !defined BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
74#else // BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 1
75
76template <typename T, T N>
77using make_integer_sequence = std::make_integer_sequence<T, N>;
78
79#endif // BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 1
80
81template <std::size_t N>
82using make_index_sequence = make_integer_sequence<std::size_t, N>;
83
84template <typename... T>
85using index_sequence_for = make_index_sequence<sizeof...(T)>;
86
87}}} // namespace boost::pfr::detail
88
89#endif
90