mirror of
https://github.com/nlohmann/json.git
synced 2025-06-13 10:12:53 +08:00

Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled
macOS / macos-13 (14.1) (push) Has been cancelled
macOS / macos-13 (14.2) (push) Has been cancelled
macOS / macos-13 (14.3) (push) Has been cancelled
macOS / macos-13 (14.3.1) (push) Has been cancelled
macOS / macos-13 (15.0.1) (push) Has been cancelled
macOS / macos-13 (15.1) (push) Has been cancelled
macOS / macos-13 (15.2) (push) Has been cancelled
macOS / macos-14 (15.3) (push) Has been cancelled
macOS / macos-14 (15.4) (push) Has been cancelled
macOS / macos-15 (16.0) (push) Has been cancelled
macOS / macos-15 (16.1) (push) Has been cancelled
macOS / xcode_standards (11) (push) Has been cancelled
macOS / xcode_standards (14) (push) Has been cancelled
macOS / xcode_standards (17) (push) Has been cancelled
macOS / xcode_standards (20) (push) Has been cancelled
macOS / xcode_standards (23) (push) Has been cancelled
Publish documentation / publish_documentation (push) Has been cancelled
Ubuntu / ci_test_clang (push) Has been cancelled
Ubuntu / ci_test_gcc (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_cppcheck) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_infer) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_single_binaries) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_amalgamation) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_single_header) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_valgrind) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_cpplint) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_non_git_tests) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_offline_testdata) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_reproducible_tests) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_clang_analyze) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_clang_tidy) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_test_clang_sanitizer) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_cmake_flags) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_diagnostics) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_legacycomparison) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noexceptions) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noglobaludls) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noimplicitconversions) (push) Has been cancelled
Ubuntu / ci_test_coverage (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (4.8) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (4.9) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (5) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (6) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (10) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (11) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (12) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (13) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (14) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (7) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (8) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (9) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (latest) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (10) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (11) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (12) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (13) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (14) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (15-bullseye) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (16) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (17) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (18) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (19) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.5) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.6) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.7) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.8) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.9) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (4) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (5) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (6) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (7) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (8) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (9) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (latest) (push) Has been cancelled
Ubuntu / ci_test_compilers (g++-4.8) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (11) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (14) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (17) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (20) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (23) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (11, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (11, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (14, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (14, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (17, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (17, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (20, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (20, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (23, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (23, libstdcxx) (push) Has been cancelled
Ubuntu / ci_cuda_example (push) Has been cancelled
Ubuntu / ci_icpc (push) Has been cancelled
Ubuntu / ci_reuse_compliance (push) Has been cancelled
Ubuntu / ci_test_documentation (ci_test_api_documentation) (push) Has been cancelled
Ubuntu / ci_test_documentation (ci_test_examples) (push) Has been cancelled
Windows / mingw (x64) (push) Has been cancelled
Windows / mingw (x86) (push) Has been cancelled
Windows / msvc2019 (Win32, Debug) (push) Has been cancelled
Windows / msvc2019 (Win32, Release) (push) Has been cancelled
Windows / msvc2019 (x64, Debug) (push) Has been cancelled
Windows / msvc2019 (x64, Release) (push) Has been cancelled
Windows / msvc2019_latest (push) Has been cancelled
Windows / msvc2022 (Win32, Debug) (push) Has been cancelled
Windows / msvc2022 (Win32, Release) (push) Has been cancelled
Windows / msvc2022 (x64, Debug) (push) Has been cancelled
Windows / msvc2022 (x64, Release) (push) Has been cancelled
Windows / msvc2022_latest (push) Has been cancelled
Windows / clang (11) (push) Has been cancelled
Windows / clang (12) (push) Has been cancelled
Windows / clang (13) (push) Has been cancelled
Windows / clang (14) (push) Has been cancelled
Windows / clang (15) (push) Has been cancelled
Windows / clang-cl-11 (Win32) (push) Has been cancelled
Windows / clang-cl-11 (x64) (push) Has been cancelled
* 📄 update licenses * 📄 update licenses
172 lines
5.1 KiB
C++
172 lines
5.1 KiB
C++
// __ _____ _____ _____
|
|
// __| | __| | | | JSON for Modern C++
|
|
// | | |__ | | | | | | version 3.11.3
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
//
|
|
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
|
// SPDX-FileCopyrightText: 2018 The Abseil Authors
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <array> // array
|
|
#include <cstddef> // size_t
|
|
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
|
|
#include <utility> // index_sequence, make_index_sequence, index_sequence_for
|
|
|
|
#include <nlohmann/detail/macro_scope.hpp>
|
|
|
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
|
namespace detail
|
|
{
|
|
|
|
template<typename T>
|
|
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
|
|
|
#ifdef JSON_HAS_CPP_14
|
|
|
|
// the following utilities are natively available in C++14
|
|
using std::enable_if_t;
|
|
using std::index_sequence;
|
|
using std::make_index_sequence;
|
|
using std::index_sequence_for;
|
|
|
|
#else
|
|
|
|
// alias templates to reduce boilerplate
|
|
template<bool B, typename T = void>
|
|
using enable_if_t = typename std::enable_if<B, T>::type;
|
|
|
|
// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h
|
|
// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0.
|
|
|
|
//// START OF CODE FROM GOOGLE ABSEIL
|
|
|
|
// integer_sequence
|
|
//
|
|
// Class template representing a compile-time integer sequence. An instantiation
|
|
// of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its
|
|
// type through its template arguments (which is a common need when
|
|
// working with C++11 variadic templates). `absl::integer_sequence` is designed
|
|
// to be a drop-in replacement for C++14's `std::integer_sequence`.
|
|
//
|
|
// Example:
|
|
//
|
|
// template< class T, T... Ints >
|
|
// void user_function(integer_sequence<T, Ints...>);
|
|
//
|
|
// int main()
|
|
// {
|
|
// // user_function's `T` will be deduced to `int` and `Ints...`
|
|
// // will be deduced to `0, 1, 2, 3, 4`.
|
|
// user_function(make_integer_sequence<int, 5>());
|
|
// }
|
|
template <typename T, T... Ints>
|
|
struct integer_sequence
|
|
{
|
|
using value_type = T;
|
|
static constexpr std::size_t size() noexcept
|
|
{
|
|
return sizeof...(Ints);
|
|
}
|
|
};
|
|
|
|
// index_sequence
|
|
//
|
|
// A helper template for an `integer_sequence` of `size_t`,
|
|
// `absl::index_sequence` is designed to be a drop-in replacement for C++14's
|
|
// `std::index_sequence`.
|
|
template <size_t... Ints>
|
|
using index_sequence = integer_sequence<size_t, Ints...>;
|
|
|
|
namespace utility_internal
|
|
{
|
|
|
|
template <typename Seq, size_t SeqSize, size_t Rem>
|
|
struct Extend;
|
|
|
|
// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency.
|
|
template <typename T, T... Ints, size_t SeqSize>
|
|
struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
|
|
{
|
|
using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
|
|
};
|
|
|
|
template <typename T, T... Ints, size_t SeqSize>
|
|
struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
|
|
{
|
|
using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
|
|
};
|
|
|
|
// Recursion helper for 'make_integer_sequence<T, N>'.
|
|
// 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'.
|
|
template <typename T, size_t N>
|
|
struct Gen
|
|
{
|
|
using type =
|
|
typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
|
|
};
|
|
|
|
template <typename T>
|
|
struct Gen<T, 0>
|
|
{
|
|
using type = integer_sequence<T>;
|
|
};
|
|
|
|
} // namespace utility_internal
|
|
|
|
// Compile-time sequences of integers
|
|
|
|
// make_integer_sequence
|
|
//
|
|
// This template alias is equivalent to
|
|
// `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in
|
|
// replacement for C++14's `std::make_integer_sequence`.
|
|
template <typename T, T N>
|
|
using make_integer_sequence = typename utility_internal::Gen<T, N>::type;
|
|
|
|
// make_index_sequence
|
|
//
|
|
// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,
|
|
// and is designed to be a drop-in replacement for C++14's
|
|
// `std::make_index_sequence`.
|
|
template <size_t N>
|
|
using make_index_sequence = make_integer_sequence<size_t, N>;
|
|
|
|
// index_sequence_for
|
|
//
|
|
// Converts a typename pack into an index sequence of the same length, and
|
|
// is designed to be a drop-in replacement for C++14's
|
|
// `std::index_sequence_for()`
|
|
template <typename... Ts>
|
|
using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
|
|
|
|
//// END OF CODE FROM GOOGLE ABSEIL
|
|
|
|
#endif
|
|
|
|
// dispatch utility (taken from ranges-v3)
|
|
template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
|
|
template<> struct priority_tag<0> {};
|
|
|
|
// taken from ranges-v3
|
|
template<typename T>
|
|
struct static_const
|
|
{
|
|
static JSON_INLINE_VARIABLE constexpr T value{};
|
|
};
|
|
|
|
#ifndef JSON_HAS_CPP_17
|
|
template<typename T>
|
|
constexpr T static_const<T>::value;
|
|
#endif
|
|
|
|
template<typename T, typename... Args>
|
|
constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
|
|
{
|
|
return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};
|
|
}
|
|
|
|
} // namespace detail
|
|
NLOHMANN_JSON_NAMESPACE_END
|