Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:38

0001 // Copyright (c) 2018 Sergei Fedorov
0002 // Copyright (c) 2019-2023 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 #include <type_traits>
0014 #include <utility>
0015 #include <cstddef>
0016 
0017 namespace boost { namespace pfr { namespace detail {
0018 
0019 #if BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 0
0020 
0021 #ifdef __has_builtin
0022 #   if __has_builtin(__make_integer_seq)
0023 #       define BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
0024 #   endif
0025 #endif
0026 
0027 #ifdef BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
0028 
0029 using std::integer_sequence;
0030 
0031 // Clang unable to use namespace qualified std::integer_sequence in __make_integer_seq.
0032 template <typename T, T N>
0033 using make_integer_sequence = __make_integer_seq<integer_sequence, T, N>;
0034 
0035 #undef BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
0036 
0037 #else
0038 
0039 template <typename T, typename U>
0040 struct join_sequences;
0041 
0042 template <typename T, T... A, T... B>
0043 struct join_sequences<std::integer_sequence<T, A...>, std::integer_sequence<T, B...>> {
0044     using type = std::integer_sequence<T, A..., B...>;
0045 };
0046 
0047 template <typename T, T Min, T Max>
0048 struct build_sequence_impl {
0049     static_assert(Min < Max, "Start of range must be less than its end");
0050     static constexpr T size = Max - Min;
0051     using type = typename join_sequences<
0052             typename build_sequence_impl<T, Min, Min + size / 2>::type,
0053             typename build_sequence_impl<T, Min + size / 2 + 1, Max>::type
0054         >::type;
0055 };
0056 
0057 template <typename T, T V>
0058 struct build_sequence_impl<T, V, V> {
0059     using type = std::integer_sequence<T, V>;
0060 };
0061 
0062 template <typename T, std::size_t N>
0063 struct make_integer_sequence_impl : build_sequence_impl<T, 0, N - 1> {};
0064 
0065 template <typename T>
0066 struct make_integer_sequence_impl<T, 0> {
0067     using type = std::integer_sequence<T>;
0068 };
0069 
0070 template <typename T, T N>
0071 using make_integer_sequence = typename make_integer_sequence_impl<T, N>::type;
0072 
0073 #endif // !defined BOOST_PFR_USE_MAKE_INTEGER_SEQ_BUILTIN
0074 #else // BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 1
0075 
0076 template <typename T, T N>
0077 using make_integer_sequence = std::make_integer_sequence<T, N>;
0078 
0079 #endif // BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == 1
0080 
0081 template <std::size_t N>
0082 using make_index_sequence = make_integer_sequence<std::size_t, N>;
0083 
0084 template <typename... T>
0085 using index_sequence_for = make_index_sequence<sizeof...(T)>;
0086 
0087 }}} // namespace boost::pfr::detail
0088 
0089 #endif
0090