Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:19

0001 //     __ _____ _____ _____
0002 //  __|  |   __|     |   | |  JSON for Modern C++
0003 // |  |  |__   |  |  | | | |  version 3.11.2
0004 // |_____|_____|_____|_|___|  https://github.com/nlohmann/json
0005 //
0006 // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
0007 // SPDX-FileCopyrightText: 2018 The Abseil Authors
0008 // SPDX-License-Identifier: MIT
0009 
0010 #pragma once
0011 
0012 #include <array> // array
0013 #include <cstddef> // size_t
0014 #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
0015 #include <utility> // index_sequence, make_index_sequence, index_sequence_for
0016 
0017 #include <nlohmann/detail/macro_scope.hpp>
0018 
0019 NLOHMANN_JSON_NAMESPACE_BEGIN
0020 namespace detail
0021 {
0022 
0023 template<typename T>
0024 using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
0025 
0026 #ifdef JSON_HAS_CPP_14
0027 
0028 // the following utilities are natively available in C++14
0029 using std::enable_if_t;
0030 using std::index_sequence;
0031 using std::make_index_sequence;
0032 using std::index_sequence_for;
0033 
0034 #else
0035 
0036 // alias templates to reduce boilerplate
0037 template<bool B, typename T = void>
0038 using enable_if_t = typename std::enable_if<B, T>::type;
0039 
0040 // The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h
0041 // which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0.
0042 
0043 //// START OF CODE FROM GOOGLE ABSEIL
0044 
0045 // integer_sequence
0046 //
0047 // Class template representing a compile-time integer sequence. An instantiation
0048 // of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its
0049 // type through its template arguments (which is a common need when
0050 // working with C++11 variadic templates). `absl::integer_sequence` is designed
0051 // to be a drop-in replacement for C++14's `std::integer_sequence`.
0052 //
0053 // Example:
0054 //
0055 //   template< class T, T... Ints >
0056 //   void user_function(integer_sequence<T, Ints...>);
0057 //
0058 //   int main()
0059 //   {
0060 //     // user_function's `T` will be deduced to `int` and `Ints...`
0061 //     // will be deduced to `0, 1, 2, 3, 4`.
0062 //     user_function(make_integer_sequence<int, 5>());
0063 //   }
0064 template <typename T, T... Ints>
0065 struct integer_sequence
0066 {
0067     using value_type = T;
0068     static constexpr std::size_t size() noexcept
0069     {
0070         return sizeof...(Ints);
0071     }
0072 };
0073 
0074 // index_sequence
0075 //
0076 // A helper template for an `integer_sequence` of `size_t`,
0077 // `absl::index_sequence` is designed to be a drop-in replacement for C++14's
0078 // `std::index_sequence`.
0079 template <size_t... Ints>
0080 using index_sequence = integer_sequence<size_t, Ints...>;
0081 
0082 namespace utility_internal
0083 {
0084 
0085 template <typename Seq, size_t SeqSize, size_t Rem>
0086 struct Extend;
0087 
0088 // Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency.
0089 template <typename T, T... Ints, size_t SeqSize>
0090 struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
0091 {
0092     using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
0093 };
0094 
0095 template <typename T, T... Ints, size_t SeqSize>
0096 struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
0097 {
0098     using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
0099 };
0100 
0101 // Recursion helper for 'make_integer_sequence<T, N>'.
0102 // 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'.
0103 template <typename T, size_t N>
0104 struct Gen
0105 {
0106     using type =
0107         typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
0108 };
0109 
0110 template <typename T>
0111 struct Gen<T, 0>
0112 {
0113     using type = integer_sequence<T>;
0114 };
0115 
0116 }  // namespace utility_internal
0117 
0118 // Compile-time sequences of integers
0119 
0120 // make_integer_sequence
0121 //
0122 // This template alias is equivalent to
0123 // `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in
0124 // replacement for C++14's `std::make_integer_sequence`.
0125 template <typename T, T N>
0126 using make_integer_sequence = typename utility_internal::Gen<T, N>::type;
0127 
0128 // make_index_sequence
0129 //
0130 // This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,
0131 // and is designed to be a drop-in replacement for C++14's
0132 // `std::make_index_sequence`.
0133 template <size_t N>
0134 using make_index_sequence = make_integer_sequence<size_t, N>;
0135 
0136 // index_sequence_for
0137 //
0138 // Converts a typename pack into an index sequence of the same length, and
0139 // is designed to be a drop-in replacement for C++14's
0140 // `std::index_sequence_for()`
0141 template <typename... Ts>
0142 using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
0143 
0144 //// END OF CODE FROM GOOGLE ABSEIL
0145 
0146 #endif
0147 
0148 // dispatch utility (taken from ranges-v3)
0149 template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
0150 template<> struct priority_tag<0> {};
0151 
0152 // taken from ranges-v3
0153 template<typename T>
0154 struct static_const
0155 {
0156     static JSON_INLINE_VARIABLE constexpr T value{};
0157 };
0158 
0159 #ifndef JSON_HAS_CPP_17
0160     template<typename T>
0161     constexpr T static_const<T>::value;
0162 #endif
0163 
0164 template<typename T, typename... Args>
0165 inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
0166 {
0167     return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};
0168 }
0169 
0170 }  // namespace detail
0171 NLOHMANN_JSON_NAMESPACE_END