Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:54:35

0001 // Copyright (c) 2018 Sergei Fedorov
0002 // Copyright (c) 2019-2025 Antony Polukhin
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_PFR_DETAIL_MAKE_INTEGER_SEQUENCE_HPP
0008 #define BOOST_PFR_DETAIL_MAKE_INTEGER_SEQUENCE_HPP
0009 #pragma once
0010 
0011 #include <boost/pfr/detail/config.hpp>
0012 
0013 #ifdef BOOST_PFR_HAS_STD_MODULE
0014 import std;
0015 #else
0016 #include <type_traits>
0017 #include <utility>
0018 #include <cstddef>
0019 #endif
0020 
0021 namespace boost { namespace pfr { namespace detail {
0022 
0023 #if BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 0
0024 
0025 #ifdef __has_builtin
0026 #   if __has_builtin(__make_integer_seq)
0027 #       define BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
0028 #   endif
0029 #endif
0030 
0031 #ifdef BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
0032 
0033 using std::integer_sequence;
0034 
0035 // Clang unable to use namespace qualified std::integer_sequence in __make_integer_seq.
0036 template <typename T, T N>
0037 using make_integer_sequence = __make_integer_seq<integer_sequence, T, N>;
0038 
0039 #undef BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
0040 
0041 #else
0042 
0043 template <typename T, typename U>
0044 struct join_sequences;
0045 
0046 template <typename T, T... A, T... B>
0047 struct join_sequences<std::integer_sequence<T, A...>, std::integer_sequence<T, B...>> {
0048     using type = std::integer_sequence<T, A..., B...>;
0049 };
0050 
0051 template <typename T, T Min, T Max>
0052 struct build_sequence_impl {
0053     static_assert(Min < Max, "Start of range must be less than its end");
0054     static constexpr T size = Max - Min;
0055     using type = typename join_sequences<
0056             typename build_sequence_impl<T, Min, Min + size / 2>::type,
0057             typename build_sequence_impl<T, Min + size / 2 + 1, Max>::type
0058         >::type;
0059 };
0060 
0061 template <typename T, T V>
0062 struct build_sequence_impl<T, V, V> {
0063     using type = std::integer_sequence<T, V>;
0064 };
0065 
0066 template <typename T, std::size_t N>
0067 struct make_integer_sequence_impl : build_sequence_impl<T, 0, N - 1> {};
0068 
0069 template <typename T>
0070 struct make_integer_sequence_impl<T, 0> {
0071     using type = std::integer_sequence<T>;
0072 };
0073 
0074 template <typename T, T N>
0075 using make_integer_sequence = typename make_integer_sequence_impl<T, N>::type;
0076 
0077 #endif // !defined BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
0078 #else // BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 1
0079 
0080 template <typename T, T N>
0081 using make_integer_sequence = std::make_integer_sequence<T, N>;
0082 
0083 #endif // BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 1
0084 
0085 template <std::size_t N>
0086 using make_index_sequence = make_integer_sequence<std::size_t, N>;
0087 
0088 template <typename... T>
0089 using index_sequence_for = make_index_sequence<sizeof...(T)>;
0090 
0091 }}} // namespace boost::pfr::detail
0092 
0093 #endif
0094