1c5f01b2fSopenharmony_ci// __ _____ _____ _____ 2c5f01b2fSopenharmony_ci// __| | __| | | | JSON for Modern C++ 3c5f01b2fSopenharmony_ci// | | |__ | | | | | | version 3.11.2 4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___| https://github.com/nlohmann/json 5c5f01b2fSopenharmony_ci// 6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> 7c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2018 The Abseil Authors 8c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT 9c5f01b2fSopenharmony_ci 10c5f01b2fSopenharmony_ci#pragma once 11c5f01b2fSopenharmony_ci 12c5f01b2fSopenharmony_ci#include <array> // array 13c5f01b2fSopenharmony_ci#include <cstddef> // size_t 14c5f01b2fSopenharmony_ci#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type 15c5f01b2fSopenharmony_ci#include <utility> // index_sequence, make_index_sequence, index_sequence_for 16c5f01b2fSopenharmony_ci 17c5f01b2fSopenharmony_ci#include <nlohmann/detail/macro_scope.hpp> 18c5f01b2fSopenharmony_ci 19c5f01b2fSopenharmony_ciNLOHMANN_JSON_NAMESPACE_BEGIN 20c5f01b2fSopenharmony_cinamespace detail 21c5f01b2fSopenharmony_ci{ 22c5f01b2fSopenharmony_ci 23c5f01b2fSopenharmony_citemplate<typename T> 24c5f01b2fSopenharmony_ciusing uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; 25c5f01b2fSopenharmony_ci 26c5f01b2fSopenharmony_ci#ifdef JSON_HAS_CPP_14 27c5f01b2fSopenharmony_ci 28c5f01b2fSopenharmony_ci// the following utilities are natively available in C++14 29c5f01b2fSopenharmony_ciusing std::enable_if_t; 30c5f01b2fSopenharmony_ciusing std::index_sequence; 31c5f01b2fSopenharmony_ciusing std::make_index_sequence; 32c5f01b2fSopenharmony_ciusing std::index_sequence_for; 33c5f01b2fSopenharmony_ci 34c5f01b2fSopenharmony_ci#else 35c5f01b2fSopenharmony_ci 36c5f01b2fSopenharmony_ci// alias templates to reduce boilerplate 37c5f01b2fSopenharmony_citemplate<bool B, typename T = void> 38c5f01b2fSopenharmony_ciusing enable_if_t = typename std::enable_if<B, T>::type; 39c5f01b2fSopenharmony_ci 40c5f01b2fSopenharmony_ci// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h 41c5f01b2fSopenharmony_ci// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. 42c5f01b2fSopenharmony_ci 43c5f01b2fSopenharmony_ci//// START OF CODE FROM GOOGLE ABSEIL 44c5f01b2fSopenharmony_ci 45c5f01b2fSopenharmony_ci// integer_sequence 46c5f01b2fSopenharmony_ci// 47c5f01b2fSopenharmony_ci// Class template representing a compile-time integer sequence. An instantiation 48c5f01b2fSopenharmony_ci// of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its 49c5f01b2fSopenharmony_ci// type through its template arguments (which is a common need when 50c5f01b2fSopenharmony_ci// working with C++11 variadic templates). `absl::integer_sequence` is designed 51c5f01b2fSopenharmony_ci// to be a drop-in replacement for C++14's `std::integer_sequence`. 52c5f01b2fSopenharmony_ci// 53c5f01b2fSopenharmony_ci// Example: 54c5f01b2fSopenharmony_ci// 55c5f01b2fSopenharmony_ci// template< class T, T... Ints > 56c5f01b2fSopenharmony_ci// void user_function(integer_sequence<T, Ints...>); 57c5f01b2fSopenharmony_ci// 58c5f01b2fSopenharmony_ci// int main() 59c5f01b2fSopenharmony_ci// { 60c5f01b2fSopenharmony_ci// // user_function's `T` will be deduced to `int` and `Ints...` 61c5f01b2fSopenharmony_ci// // will be deduced to `0, 1, 2, 3, 4`. 62c5f01b2fSopenharmony_ci// user_function(make_integer_sequence<int, 5>()); 63c5f01b2fSopenharmony_ci// } 64c5f01b2fSopenharmony_citemplate <typename T, T... Ints> 65c5f01b2fSopenharmony_cistruct integer_sequence 66c5f01b2fSopenharmony_ci{ 67c5f01b2fSopenharmony_ci using value_type = T; 68c5f01b2fSopenharmony_ci static constexpr std::size_t size() noexcept 69c5f01b2fSopenharmony_ci { 70c5f01b2fSopenharmony_ci return sizeof...(Ints); 71c5f01b2fSopenharmony_ci } 72c5f01b2fSopenharmony_ci}; 73c5f01b2fSopenharmony_ci 74c5f01b2fSopenharmony_ci// index_sequence 75c5f01b2fSopenharmony_ci// 76c5f01b2fSopenharmony_ci// A helper template for an `integer_sequence` of `size_t`, 77c5f01b2fSopenharmony_ci// `absl::index_sequence` is designed to be a drop-in replacement for C++14's 78c5f01b2fSopenharmony_ci// `std::index_sequence`. 79c5f01b2fSopenharmony_citemplate <size_t... Ints> 80c5f01b2fSopenharmony_ciusing index_sequence = integer_sequence<size_t, Ints...>; 81c5f01b2fSopenharmony_ci 82c5f01b2fSopenharmony_cinamespace utility_internal 83c5f01b2fSopenharmony_ci{ 84c5f01b2fSopenharmony_ci 85c5f01b2fSopenharmony_citemplate <typename Seq, size_t SeqSize, size_t Rem> 86c5f01b2fSopenharmony_cistruct Extend; 87c5f01b2fSopenharmony_ci 88c5f01b2fSopenharmony_ci// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. 89c5f01b2fSopenharmony_citemplate <typename T, T... Ints, size_t SeqSize> 90c5f01b2fSopenharmony_cistruct Extend<integer_sequence<T, Ints...>, SeqSize, 0> 91c5f01b2fSopenharmony_ci{ 92c5f01b2fSopenharmony_ci using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >; 93c5f01b2fSopenharmony_ci}; 94c5f01b2fSopenharmony_ci 95c5f01b2fSopenharmony_citemplate <typename T, T... Ints, size_t SeqSize> 96c5f01b2fSopenharmony_cistruct Extend<integer_sequence<T, Ints...>, SeqSize, 1> 97c5f01b2fSopenharmony_ci{ 98c5f01b2fSopenharmony_ci using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >; 99c5f01b2fSopenharmony_ci}; 100c5f01b2fSopenharmony_ci 101c5f01b2fSopenharmony_ci// Recursion helper for 'make_integer_sequence<T, N>'. 102c5f01b2fSopenharmony_ci// 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'. 103c5f01b2fSopenharmony_citemplate <typename T, size_t N> 104c5f01b2fSopenharmony_cistruct Gen 105c5f01b2fSopenharmony_ci{ 106c5f01b2fSopenharmony_ci using type = 107c5f01b2fSopenharmony_ci typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type; 108c5f01b2fSopenharmony_ci}; 109c5f01b2fSopenharmony_ci 110c5f01b2fSopenharmony_citemplate <typename T> 111c5f01b2fSopenharmony_cistruct Gen<T, 0> 112c5f01b2fSopenharmony_ci{ 113c5f01b2fSopenharmony_ci using type = integer_sequence<T>; 114c5f01b2fSopenharmony_ci}; 115c5f01b2fSopenharmony_ci 116c5f01b2fSopenharmony_ci} // namespace utility_internal 117c5f01b2fSopenharmony_ci 118c5f01b2fSopenharmony_ci// Compile-time sequences of integers 119c5f01b2fSopenharmony_ci 120c5f01b2fSopenharmony_ci// make_integer_sequence 121c5f01b2fSopenharmony_ci// 122c5f01b2fSopenharmony_ci// This template alias is equivalent to 123c5f01b2fSopenharmony_ci// `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in 124c5f01b2fSopenharmony_ci// replacement for C++14's `std::make_integer_sequence`. 125c5f01b2fSopenharmony_citemplate <typename T, T N> 126c5f01b2fSopenharmony_ciusing make_integer_sequence = typename utility_internal::Gen<T, N>::type; 127c5f01b2fSopenharmony_ci 128c5f01b2fSopenharmony_ci// make_index_sequence 129c5f01b2fSopenharmony_ci// 130c5f01b2fSopenharmony_ci// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, 131c5f01b2fSopenharmony_ci// and is designed to be a drop-in replacement for C++14's 132c5f01b2fSopenharmony_ci// `std::make_index_sequence`. 133c5f01b2fSopenharmony_citemplate <size_t N> 134c5f01b2fSopenharmony_ciusing make_index_sequence = make_integer_sequence<size_t, N>; 135c5f01b2fSopenharmony_ci 136c5f01b2fSopenharmony_ci// index_sequence_for 137c5f01b2fSopenharmony_ci// 138c5f01b2fSopenharmony_ci// Converts a typename pack into an index sequence of the same length, and 139c5f01b2fSopenharmony_ci// is designed to be a drop-in replacement for C++14's 140c5f01b2fSopenharmony_ci// `std::index_sequence_for()` 141c5f01b2fSopenharmony_citemplate <typename... Ts> 142c5f01b2fSopenharmony_ciusing index_sequence_for = make_index_sequence<sizeof...(Ts)>; 143c5f01b2fSopenharmony_ci 144c5f01b2fSopenharmony_ci//// END OF CODE FROM GOOGLE ABSEIL 145c5f01b2fSopenharmony_ci 146c5f01b2fSopenharmony_ci#endif 147c5f01b2fSopenharmony_ci 148c5f01b2fSopenharmony_ci// dispatch utility (taken from ranges-v3) 149c5f01b2fSopenharmony_citemplate<unsigned N> struct priority_tag : priority_tag < N - 1 > {}; 150c5f01b2fSopenharmony_citemplate<> struct priority_tag<0> {}; 151c5f01b2fSopenharmony_ci 152c5f01b2fSopenharmony_ci// taken from ranges-v3 153c5f01b2fSopenharmony_citemplate<typename T> 154c5f01b2fSopenharmony_cistruct static_const 155c5f01b2fSopenharmony_ci{ 156c5f01b2fSopenharmony_ci static JSON_INLINE_VARIABLE constexpr T value{}; 157c5f01b2fSopenharmony_ci}; 158c5f01b2fSopenharmony_ci 159c5f01b2fSopenharmony_ci#ifndef JSON_HAS_CPP_17 160c5f01b2fSopenharmony_ci template<typename T> 161c5f01b2fSopenharmony_ci constexpr T static_const<T>::value; 162c5f01b2fSopenharmony_ci#endif 163c5f01b2fSopenharmony_ci 164c5f01b2fSopenharmony_citemplate<typename T, typename... Args> 165c5f01b2fSopenharmony_ciinline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args) 166c5f01b2fSopenharmony_ci{ 167c5f01b2fSopenharmony_ci return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}}; 168c5f01b2fSopenharmony_ci} 169c5f01b2fSopenharmony_ci 170c5f01b2fSopenharmony_ci} // namespace detail 171c5f01b2fSopenharmony_ciNLOHMANN_JSON_NAMESPACE_END 172