2022-07-20 12:38:07 +02:00
|
|
|
// __ _____ _____ _____
|
|
|
|
// __| | __| | | | JSON for Modern C++
|
2023-11-28 22:36:31 +01:00
|
|
|
// | | |__ | | | | | | version 3.11.3
|
2022-07-20 12:38:07 +02:00
|
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
|
|
//
|
2023-11-26 15:51:19 +01:00
|
|
|
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
2022-07-20 12:38:07 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2018-01-10 10:18:31 +01:00
|
|
|
#pragma once
|
2017-08-14 15:06:35 +02:00
|
|
|
|
2017-08-14 19:28:01 +02:00
|
|
|
#include <limits> // numeric_limits
|
2018-07-24 13:22:44 +02:00
|
|
|
#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
|
2017-08-14 19:28:01 +02:00
|
|
|
#include <utility> // declval
|
2020-12-26 17:56:16 +01:00
|
|
|
#include <tuple> // tuple
|
2023-11-27 06:51:25 +01:00
|
|
|
#include <string> // char_traits
|
2017-08-14 15:06:35 +02:00
|
|
|
|
2021-10-07 12:32:25 +02:00
|
|
|
#include <nlohmann/detail/iterators/iterator_traits.hpp>
|
2022-07-30 21:59:13 +02:00
|
|
|
#include <nlohmann/detail/macro_scope.hpp>
|
2021-10-07 12:32:25 +02:00
|
|
|
#include <nlohmann/detail/meta/call_std/begin.hpp>
|
|
|
|
#include <nlohmann/detail/meta/call_std/end.hpp>
|
2018-07-24 13:22:44 +02:00
|
|
|
#include <nlohmann/detail/meta/cpp_future.hpp>
|
2018-09-05 16:02:13 +02:00
|
|
|
#include <nlohmann/detail/meta/detected.hpp>
|
2019-03-17 12:01:49 +01:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2017-08-14 15:06:35 +02:00
|
|
|
|
2022-07-30 21:59:13 +02:00
|
|
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
2017-08-14 15:06:35 +02:00
|
|
|
/*!
|
|
|
|
@brief detail namespace with internal helper functions
|
|
|
|
|
|
|
|
This namespace collects functions that should not be exposed,
|
|
|
|
implementations of some @ref basic_json methods, and meta-programming helpers.
|
|
|
|
|
|
|
|
@since version 2.1.0
|
|
|
|
*/
|
|
|
|
namespace detail
|
|
|
|
{
|
2022-07-30 21:59:13 +02:00
|
|
|
|
2017-08-14 15:06:35 +02:00
|
|
|
/////////////
|
|
|
|
// helpers //
|
|
|
|
/////////////
|
|
|
|
|
2018-10-17 12:03:10 +02:00
|
|
|
// Note to maintainers:
|
|
|
|
//
|
|
|
|
// Every trait in this file expects a non CV-qualified type.
|
|
|
|
// The only exceptions are in the 'aliases for detected' section
|
|
|
|
// (i.e. those of the form: decltype(T::member_function(std::declval<T>())))
|
|
|
|
//
|
|
|
|
// In this case, T has to be properly CV-qualified to constraint the function arguments
|
|
|
|
// (e.g. to_json(BasicJsonType&, const T&))
|
|
|
|
|
2017-08-14 15:06:35 +02:00
|
|
|
template<typename> struct is_basic_json : std::false_type {};
|
|
|
|
|
|
|
|
NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
|
|
|
struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
|
2022-04-12 14:18:16 +02:00
|
|
|
|
|
|
|
// used by exceptions create() member functions
|
|
|
|
// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t
|
|
|
|
// false_type otherwise
|
|
|
|
template<typename BasicJsonContext>
|
|
|
|
struct is_basic_json_context :
|
|
|
|
std::integral_constant < bool,
|
|
|
|
is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
|
|
|
|
|| std::is_same<BasicJsonContext, std::nullptr_t>::value >
|
|
|
|
{};
|
|
|
|
|
2020-04-12 21:32:39 +02:00
|
|
|
//////////////////////
|
2020-04-12 22:42:26 +02:00
|
|
|
// json_ref helpers //
|
2020-04-12 21:32:39 +02:00
|
|
|
//////////////////////
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename>
|
2020-04-12 21:32:39 +02:00
|
|
|
class json_ref;
|
|
|
|
|
|
|
|
template<typename>
|
|
|
|
struct is_json_ref : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2020-04-12 21:32:39 +02:00
|
|
|
struct is_json_ref<json_ref<T>> : std::true_type {};
|
|
|
|
|
2018-09-05 16:02:13 +02:00
|
|
|
//////////////////////////
|
|
|
|
// aliases for detected //
|
|
|
|
//////////////////////////
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-09-05 16:02:13 +02:00
|
|
|
using mapped_type_t = typename T::mapped_type;
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-09-05 16:02:13 +02:00
|
|
|
using key_type_t = typename T::key_type;
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-09-05 16:02:13 +02:00
|
|
|
using value_type_t = typename T::value_type;
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-09-07 12:42:49 +02:00
|
|
|
using difference_type_t = typename T::difference_type;
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-09-07 12:42:49 +02:00
|
|
|
using pointer_t = typename T::pointer;
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-09-07 12:42:49 +02:00
|
|
|
using reference_t = typename T::reference;
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-09-07 12:42:49 +02:00
|
|
|
using iterator_category_t = typename T::iterator_category;
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T, typename... Args>
|
2018-09-05 16:02:13 +02:00
|
|
|
using to_json_function = decltype(T::to_json(std::declval<Args>()...));
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T, typename... Args>
|
2018-09-05 16:02:13 +02:00
|
|
|
using from_json_function = decltype(T::from_json(std::declval<Args>()...));
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T, typename U>
|
2018-09-12 17:01:27 +02:00
|
|
|
using get_template_function = decltype(std::declval<T>().template get<U>());
|
|
|
|
|
2018-10-16 14:00:34 +02:00
|
|
|
// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename T, typename = void>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct has_from_json : std::false_type {};
|
|
|
|
|
2020-07-16 11:11:35 +02:00
|
|
|
// trait checking if j.get<T> is valid
|
|
|
|
// use this trait instead of std::is_constructible or std::is_convertible,
|
|
|
|
// both rely on, or make use of implicit conversions, and thus fail when T
|
|
|
|
// has several constructors/operator= (see https://github.com/nlohmann/json/issues/958)
|
|
|
|
template <typename BasicJsonType, typename T>
|
|
|
|
struct is_getable
|
|
|
|
{
|
|
|
|
static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
|
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename T>
|
2021-01-09 00:08:27 +01:00
|
|
|
struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
|
2018-10-16 14:00:34 +02:00
|
|
|
{
|
|
|
|
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
|
|
|
|
|
|
|
static constexpr bool value =
|
|
|
|
is_detected_exact<void, from_json_function, serializer,
|
|
|
|
const BasicJsonType&, T&>::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
|
|
|
|
// this overload is used for non-default-constructible user-defined-types
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename T, typename = void>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct has_non_default_from_json : std::false_type {};
|
|
|
|
|
|
|
|
template<typename BasicJsonType, typename T>
|
2020-06-03 14:20:36 +02:00
|
|
|
struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
|
2018-10-16 14:00:34 +02:00
|
|
|
{
|
|
|
|
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
|
|
|
|
|
|
|
static constexpr bool value =
|
|
|
|
is_detected_exact<T, from_json_function, serializer,
|
|
|
|
const BasicJsonType&>::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists
|
|
|
|
// Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion.
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename T, typename = void>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct has_to_json : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename T>
|
|
|
|
struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
|
2018-10-16 14:00:34 +02:00
|
|
|
{
|
|
|
|
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
|
|
|
|
|
|
|
static constexpr bool value =
|
|
|
|
is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
|
|
|
|
T>::value;
|
|
|
|
};
|
|
|
|
|
2022-04-29 21:40:02 +02:00
|
|
|
template<typename T>
|
|
|
|
using detect_key_compare = typename T::key_compare;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
|
|
|
|
|
|
|
|
// obtains the actual object key comparator
|
|
|
|
template<typename BasicJsonType>
|
|
|
|
struct actual_object_comparator
|
|
|
|
{
|
|
|
|
using object_t = typename BasicJsonType::object_t;
|
|
|
|
using object_comparator_t = typename BasicJsonType::default_object_comparator_t;
|
|
|
|
using type = typename std::conditional < has_key_compare<object_t>::value,
|
|
|
|
typename object_t::key_compare, object_comparator_t>::type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename BasicJsonType>
|
|
|
|
using actual_object_comparator_t = typename actual_object_comparator<BasicJsonType>::type;
|
2018-10-16 14:00:34 +02:00
|
|
|
|
2023-11-27 06:51:25 +01:00
|
|
|
/////////////////
|
|
|
|
// char_traits //
|
|
|
|
/////////////////
|
|
|
|
|
|
|
|
// Primary template of char_traits calls std char_traits
|
|
|
|
template<typename T>
|
|
|
|
struct char_traits : std::char_traits<T>
|
|
|
|
{};
|
|
|
|
|
|
|
|
// Explicitly define char traits for unsigned char since it is not standard
|
|
|
|
template<>
|
|
|
|
struct char_traits<unsigned char> : std::char_traits<char>
|
|
|
|
{
|
|
|
|
using char_type = unsigned char;
|
|
|
|
using int_type = uint64_t;
|
|
|
|
|
|
|
|
// Redefine to_int_type function
|
|
|
|
static int_type to_int_type(char_type c) noexcept
|
|
|
|
{
|
|
|
|
return static_cast<int_type>(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char_type to_char_type(int_type i) noexcept
|
|
|
|
{
|
|
|
|
return static_cast<char_type>(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr int_type eof() noexcept
|
|
|
|
{
|
|
|
|
return static_cast<int_type>(EOF);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Explicitly define char traits for signed char since it is not standard
|
|
|
|
template<>
|
|
|
|
struct char_traits<signed char> : std::char_traits<char>
|
|
|
|
{
|
|
|
|
using char_type = signed char;
|
|
|
|
using int_type = uint64_t;
|
|
|
|
|
|
|
|
// Redefine to_int_type function
|
|
|
|
static int_type to_int_type(char_type c) noexcept
|
|
|
|
{
|
|
|
|
return static_cast<int_type>(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char_type to_char_type(int_type i) noexcept
|
|
|
|
{
|
|
|
|
return static_cast<char_type>(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr int_type eof() noexcept
|
|
|
|
{
|
|
|
|
return static_cast<int_type>(EOF);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-05 16:02:13 +02:00
|
|
|
///////////////////
|
|
|
|
// is_ functions //
|
|
|
|
///////////////////
|
2021-01-23 18:24:47 +01:00
|
|
|
|
2021-01-12 18:28:00 +01:00
|
|
|
// https://en.cppreference.com/w/cpp/types/conjunction
|
|
|
|
template<class...> struct conjunction : std::true_type { };
|
2022-04-03 18:33:33 +02:00
|
|
|
template<class B> struct conjunction<B> : B { };
|
|
|
|
template<class B, class... Bn>
|
|
|
|
struct conjunction<B, Bn...>
|
2022-06-12 14:31:07 +02:00
|
|
|
: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
|
2021-01-12 18:28:00 +01:00
|
|
|
|
2021-06-17 19:17:43 +02:00
|
|
|
// https://en.cppreference.com/w/cpp/types/negation
|
|
|
|
template<class B> struct negation : std::integral_constant < bool, !B::value > { };
|
|
|
|
|
2021-01-12 18:28:00 +01:00
|
|
|
// Reimplementation of is_constructible and is_default_constructible, due to them being broken for
|
|
|
|
// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).
|
|
|
|
// This causes compile errors in e.g. clang 3.5 or gcc 4.9.
|
|
|
|
template <typename T>
|
|
|
|
struct is_default_constructible : std::is_default_constructible<T> {};
|
|
|
|
|
|
|
|
template <typename T1, typename T2>
|
|
|
|
struct is_default_constructible<std::pair<T1, T2>>
|
|
|
|
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
|
|
|
|
|
|
|
|
template <typename T1, typename T2>
|
|
|
|
struct is_default_constructible<const std::pair<T1, T2>>
|
|
|
|
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
struct is_default_constructible<std::tuple<Ts...>>
|
|
|
|
: conjunction<is_default_constructible<Ts>...> {};
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
struct is_default_constructible<const std::tuple<Ts...>>
|
|
|
|
: conjunction<is_default_constructible<Ts>...> {};
|
|
|
|
|
|
|
|
template <typename T, typename... Args>
|
|
|
|
struct is_constructible : std::is_constructible<T, Args...> {};
|
|
|
|
|
|
|
|
template <typename T1, typename T2>
|
|
|
|
struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
|
|
|
|
|
|
|
|
template <typename T1, typename T2>
|
|
|
|
struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T, typename = void>
|
2018-09-07 12:42:49 +02:00
|
|
|
struct is_iterator_traits : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-11-07 19:39:25 +01:00
|
|
|
struct is_iterator_traits<iterator_traits<T>>
|
2018-09-07 12:42:49 +02:00
|
|
|
{
|
|
|
|
private:
|
2018-11-07 19:39:25 +01:00
|
|
|
using traits = iterator_traits<T>;
|
2018-09-07 12:42:49 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr auto value =
|
|
|
|
is_detected<value_type_t, traits>::value &&
|
|
|
|
is_detected<difference_type_t, traits>::value &&
|
|
|
|
is_detected<pointer_t, traits>::value &&
|
|
|
|
is_detected<iterator_category_t, traits>::value &&
|
|
|
|
is_detected<reference_t, traits>::value;
|
|
|
|
};
|
|
|
|
|
2021-10-07 12:32:25 +02:00
|
|
|
template<typename T>
|
|
|
|
struct is_range
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
using t_ref = typename std::add_lvalue_reference<T>::type;
|
|
|
|
|
|
|
|
using iterator = detected_t<result_of_begin, t_ref>;
|
|
|
|
using sentinel = detected_t<result_of_end, t_ref>;
|
|
|
|
|
|
|
|
// to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator
|
|
|
|
// and https://en.cppreference.com/w/cpp/iterator/sentinel_for
|
|
|
|
// but reimplementing these would be too much work, as a lot of other concepts are used underneath
|
|
|
|
static constexpr auto is_iterator_begin =
|
|
|
|
is_iterator_traits<iterator_traits<iterator>>::value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename R>
|
|
|
|
using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
|
|
|
|
|
2020-12-14 14:58:59 +01:00
|
|
|
// The following implementation of is_complete_type is taken from
|
|
|
|
// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/
|
|
|
|
// and is written by Xiang Fan who agreed to using it in this library.
|
2018-01-17 12:17:38 +01:00
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T, typename = void>
|
2018-01-17 12:17:38 +01:00
|
|
|
struct is_complete_type : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T>
|
2018-01-17 12:17:38 +01:00
|
|
|
struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleObjectType,
|
|
|
|
typename = void>
|
2017-08-14 15:06:35 +02:00
|
|
|
struct is_compatible_object_type_impl : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleObjectType>
|
2018-09-05 16:35:30 +02:00
|
|
|
struct is_compatible_object_type_impl <
|
|
|
|
BasicJsonType, CompatibleObjectType,
|
2020-06-03 14:20:36 +02:00
|
|
|
enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
|
2018-09-05 16:35:30 +02:00
|
|
|
is_detected<key_type_t, CompatibleObjectType>::value >>
|
2017-08-14 15:06:35 +02:00
|
|
|
{
|
2018-09-05 16:35:30 +02:00
|
|
|
using object_t = typename BasicJsonType::object_t;
|
|
|
|
|
|
|
|
// macOS's is_constructible does not play well with nonesuch...
|
|
|
|
static constexpr bool value =
|
2021-01-12 18:28:00 +01:00
|
|
|
is_constructible<typename object_t::key_type,
|
2020-06-03 14:20:36 +02:00
|
|
|
typename CompatibleObjectType::key_type>::value &&
|
2021-01-12 18:28:00 +01:00
|
|
|
is_constructible<typename object_t::mapped_type,
|
2018-09-05 16:35:30 +02:00
|
|
|
typename CompatibleObjectType::mapped_type>::value;
|
2017-08-14 15:06:35 +02:00
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleObjectType>
|
2018-09-05 16:35:30 +02:00
|
|
|
struct is_compatible_object_type
|
|
|
|
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename ConstructibleObjectType,
|
|
|
|
typename = void>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct is_constructible_object_type_impl : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename ConstructibleObjectType>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct is_constructible_object_type_impl <
|
|
|
|
BasicJsonType, ConstructibleObjectType,
|
2020-06-03 14:20:36 +02:00
|
|
|
enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
|
2018-10-16 14:00:34 +02:00
|
|
|
is_detected<key_type_t, ConstructibleObjectType>::value >>
|
|
|
|
{
|
|
|
|
using object_t = typename BasicJsonType::object_t;
|
|
|
|
|
|
|
|
static constexpr bool value =
|
2021-01-12 18:28:00 +01:00
|
|
|
(is_default_constructible<ConstructibleObjectType>::value &&
|
2020-06-03 14:20:36 +02:00
|
|
|
(std::is_move_assignable<ConstructibleObjectType>::value ||
|
|
|
|
std::is_copy_assignable<ConstructibleObjectType>::value) &&
|
2021-01-12 18:28:00 +01:00
|
|
|
(is_constructible<typename ConstructibleObjectType::key_type,
|
2020-06-03 14:20:36 +02:00
|
|
|
typename object_t::key_type>::value &&
|
2019-04-01 13:09:38 +02:00
|
|
|
std::is_same <
|
|
|
|
typename object_t::mapped_type,
|
2020-06-03 14:20:36 +02:00
|
|
|
typename ConstructibleObjectType::mapped_type >::value)) ||
|
2019-04-01 13:09:38 +02:00
|
|
|
(has_from_json<BasicJsonType,
|
2020-06-03 14:20:36 +02:00
|
|
|
typename ConstructibleObjectType::mapped_type>::value ||
|
2019-04-01 13:09:38 +02:00
|
|
|
has_non_default_from_json <
|
|
|
|
BasicJsonType,
|
|
|
|
typename ConstructibleObjectType::mapped_type >::value);
|
2018-10-16 14:00:34 +02:00
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename ConstructibleObjectType>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct is_constructible_object_type
|
|
|
|
: is_constructible_object_type_impl<BasicJsonType,
|
|
|
|
ConstructibleObjectType> {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleStringType>
|
2021-10-14 19:19:46 +02:00
|
|
|
struct is_compatible_string_type
|
2018-03-15 20:35:00 +01:00
|
|
|
{
|
|
|
|
static constexpr auto value =
|
2021-01-12 18:28:00 +01:00
|
|
|
is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
|
2018-03-15 20:35:00 +01:00
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename ConstructibleStringType>
|
2021-10-14 19:19:46 +02:00
|
|
|
struct is_constructible_string_type
|
2018-10-16 14:00:34 +02:00
|
|
|
{
|
2022-05-01 22:46:45 +02:00
|
|
|
// launder type through decltype() to fix compilation failure on ICPC
|
|
|
|
#ifdef __INTEL_COMPILER
|
|
|
|
using laundered_type = decltype(std::declval<ConstructibleStringType>());
|
|
|
|
#else
|
|
|
|
using laundered_type = ConstructibleStringType;
|
|
|
|
#endif
|
|
|
|
|
2018-10-16 14:00:34 +02:00
|
|
|
static constexpr auto value =
|
2022-07-28 21:52:23 +02:00
|
|
|
conjunction <
|
|
|
|
is_constructible<laundered_type, typename BasicJsonType::string_t>,
|
|
|
|
is_detected_exact<typename BasicJsonType::string_t::value_type,
|
|
|
|
value_type_t, laundered_type >>::value;
|
2018-10-16 14:00:34 +02:00
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
|
2018-09-05 16:49:27 +02:00
|
|
|
struct is_compatible_array_type_impl : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleArrayType>
|
2018-09-05 16:49:27 +02:00
|
|
|
struct is_compatible_array_type_impl <
|
|
|
|
BasicJsonType, CompatibleArrayType,
|
2021-10-07 12:32:25 +02:00
|
|
|
enable_if_t <
|
2020-06-03 14:20:36 +02:00
|
|
|
is_detected<iterator_t, CompatibleArrayType>::value&&
|
2021-10-14 19:19:46 +02:00
|
|
|
is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
|
|
|
|
// special case for types like std::filesystem::path whose iterator's value_type are themselves
|
|
|
|
// c.f. https://github.com/nlohmann/json/pull/3073
|
|
|
|
!std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
|
2017-08-14 15:06:35 +02:00
|
|
|
{
|
2018-10-16 14:00:34 +02:00
|
|
|
static constexpr bool value =
|
2021-01-12 18:28:00 +01:00
|
|
|
is_constructible<BasicJsonType,
|
2021-10-07 12:32:25 +02:00
|
|
|
range_value_t<CompatibleArrayType>>::value;
|
2017-08-14 15:06:35 +02:00
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleArrayType>
|
2018-09-05 16:49:27 +02:00
|
|
|
struct is_compatible_array_type
|
|
|
|
: is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct is_constructible_array_type_impl : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename ConstructibleArrayType>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct is_constructible_array_type_impl <
|
|
|
|
BasicJsonType, ConstructibleArrayType,
|
|
|
|
enable_if_t<std::is_same<ConstructibleArrayType,
|
|
|
|
typename BasicJsonType::value_type>::value >>
|
|
|
|
: std::true_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename ConstructibleArrayType>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct is_constructible_array_type_impl <
|
|
|
|
BasicJsonType, ConstructibleArrayType,
|
2020-06-03 14:20:36 +02:00
|
|
|
enable_if_t < !std::is_same<ConstructibleArrayType,
|
|
|
|
typename BasicJsonType::value_type>::value&&
|
2021-10-07 12:32:25 +02:00
|
|
|
!is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
|
2021-01-12 18:28:00 +01:00
|
|
|
is_default_constructible<ConstructibleArrayType>::value&&
|
2020-06-03 14:20:36 +02:00
|
|
|
(std::is_move_assignable<ConstructibleArrayType>::value ||
|
|
|
|
std::is_copy_assignable<ConstructibleArrayType>::value)&&
|
|
|
|
is_detected<iterator_t, ConstructibleArrayType>::value&&
|
2021-10-07 12:32:25 +02:00
|
|
|
is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
|
|
|
|
is_detected<range_value_t, ConstructibleArrayType>::value&&
|
2021-10-14 19:19:46 +02:00
|
|
|
// special case for types like std::filesystem::path whose iterator's value_type are themselves
|
|
|
|
// c.f. https://github.com/nlohmann/json/pull/3073
|
|
|
|
!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
|
|
|
|
is_complete_type <
|
|
|
|
detected_t<range_value_t, ConstructibleArrayType >>::value >>
|
2018-10-16 14:00:34 +02:00
|
|
|
{
|
2021-10-07 12:32:25 +02:00
|
|
|
using value_type = range_value_t<ConstructibleArrayType>;
|
|
|
|
|
2018-10-16 14:00:34 +02:00
|
|
|
static constexpr bool value =
|
2021-10-07 12:32:25 +02:00
|
|
|
std::is_same<value_type,
|
|
|
|
typename BasicJsonType::array_t::value_type>::value ||
|
|
|
|
has_from_json<BasicJsonType,
|
|
|
|
value_type>::value ||
|
|
|
|
has_non_default_from_json <
|
|
|
|
BasicJsonType,
|
|
|
|
value_type >::value;
|
2018-10-16 14:00:34 +02:00
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename ConstructibleArrayType>
|
2018-10-16 14:00:34 +02:00
|
|
|
struct is_constructible_array_type
|
|
|
|
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType,
|
|
|
|
typename = void>
|
2017-08-14 15:06:35 +02:00
|
|
|
struct is_compatible_integer_type_impl : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
2018-09-05 16:56:45 +02:00
|
|
|
struct is_compatible_integer_type_impl <
|
|
|
|
RealIntegerType, CompatibleNumberIntegerType,
|
2020-06-03 14:20:36 +02:00
|
|
|
enable_if_t < std::is_integral<RealIntegerType>::value&&
|
|
|
|
std::is_integral<CompatibleNumberIntegerType>::value&&
|
|
|
|
!std::is_same<bool, CompatibleNumberIntegerType>::value >>
|
2017-08-14 15:06:35 +02:00
|
|
|
{
|
|
|
|
// is there an assert somewhere on overflows?
|
|
|
|
using RealLimits = std::numeric_limits<RealIntegerType>;
|
|
|
|
using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
|
|
|
|
|
|
|
|
static constexpr auto value =
|
2021-01-12 18:28:00 +01:00
|
|
|
is_constructible<RealIntegerType,
|
2020-06-03 14:20:36 +02:00
|
|
|
CompatibleNumberIntegerType>::value &&
|
|
|
|
CompatibleLimits::is_integer &&
|
2017-08-14 15:06:35 +02:00
|
|
|
RealLimits::is_signed == CompatibleLimits::is_signed;
|
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
2017-08-14 15:06:35 +02:00
|
|
|
struct is_compatible_integer_type
|
2018-09-05 16:56:45 +02:00
|
|
|
: is_compatible_integer_type_impl<RealIntegerType,
|
|
|
|
CompatibleNumberIntegerType> {};
|
2017-08-14 15:06:35 +02:00
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleType, typename = void>
|
2018-09-05 17:01:52 +02:00
|
|
|
struct is_compatible_type_impl: std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleType>
|
2018-09-05 17:01:52 +02:00
|
|
|
struct is_compatible_type_impl <
|
|
|
|
BasicJsonType, CompatibleType,
|
|
|
|
enable_if_t<is_complete_type<CompatibleType>::value >>
|
2018-01-17 12:17:38 +01:00
|
|
|
{
|
|
|
|
static constexpr bool value =
|
2018-09-05 17:01:52 +02:00
|
|
|
has_to_json<BasicJsonType, CompatibleType>::value;
|
2018-01-17 12:17:38 +01:00
|
|
|
};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename BasicJsonType, typename CompatibleType>
|
2018-01-17 12:17:38 +01:00
|
|
|
struct is_compatible_type
|
2018-09-05 17:01:52 +02:00
|
|
|
: is_compatible_type_impl<BasicJsonType, CompatibleType> {};
|
2019-10-31 18:39:01 +01:00
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T1, typename T2>
|
2019-10-31 18:39:01 +01:00
|
|
|
struct is_constructible_tuple : std::false_type {};
|
|
|
|
|
2020-06-03 14:20:36 +02:00
|
|
|
template<typename T1, typename... Args>
|
2021-01-12 18:28:00 +01:00
|
|
|
struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
|
2021-07-30 14:48:25 +02:00
|
|
|
|
2022-04-29 21:40:02 +02:00
|
|
|
template<typename BasicJsonType, typename T>
|
|
|
|
struct is_json_iterator_of : std::false_type {};
|
|
|
|
|
|
|
|
template<typename BasicJsonType>
|
|
|
|
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type {};
|
|
|
|
|
|
|
|
template<typename BasicJsonType>
|
|
|
|
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type
|
|
|
|
{};
|
|
|
|
|
|
|
|
// checks if a given type T is a template specialization of Primary
|
|
|
|
template<template <typename...> class Primary, typename T>
|
|
|
|
struct is_specialization_of : std::false_type {};
|
|
|
|
|
|
|
|
template<template <typename...> class Primary, typename... Args>
|
|
|
|
struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>;
|
|
|
|
|
|
|
|
// checks if A and B are comparable using Compare functor
|
|
|
|
template<typename Compare, typename A, typename B, typename = void>
|
|
|
|
struct is_comparable : std::false_type {};
|
|
|
|
|
|
|
|
template<typename Compare, typename A, typename B>
|
|
|
|
struct is_comparable<Compare, A, B, void_t<
|
|
|
|
decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
|
|
|
|
decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
|
|
|
|
>> : std::true_type {};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using detect_is_transparent = typename T::is_transparent;
|
|
|
|
|
2022-07-04 19:58:19 +02:00
|
|
|
// type trait to check if KeyType can be used as object key (without a BasicJsonType)
|
|
|
|
// see is_usable_as_basic_json_key_type below
|
|
|
|
template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,
|
|
|
|
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
|
|
|
|
using is_usable_as_key_type = typename std::conditional <
|
|
|
|
is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value
|
|
|
|
&& !(ExcludeObjectKeyType && std::is_same<KeyType,
|
|
|
|
ObjectKeyType>::value)
|
|
|
|
&& (!RequireTransparentComparator
|
|
|
|
|| is_detected <detect_is_transparent, Comparator>::value)
|
|
|
|
&& !is_json_pointer<KeyType>::value,
|
|
|
|
std::true_type,
|
|
|
|
std::false_type >::type;
|
|
|
|
|
2022-04-29 21:40:02 +02:00
|
|
|
// type trait to check if KeyType can be used as object key
|
|
|
|
// true if:
|
|
|
|
// - KeyType is comparable with BasicJsonType::object_t::key_type
|
|
|
|
// - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type
|
|
|
|
// - the comparator is transparent or RequireTransparentComparator is false
|
|
|
|
// - KeyType is not a JSON iterator or json_pointer
|
|
|
|
template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,
|
|
|
|
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
|
2022-07-04 19:58:19 +02:00
|
|
|
using is_usable_as_basic_json_key_type = typename std::conditional <
|
|
|
|
is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
|
|
|
|
typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
|
|
|
|
RequireTransparentComparator, ExcludeObjectKeyType>::value
|
|
|
|
&& !is_json_iterator_of<BasicJsonType, KeyType>::value,
|
|
|
|
std::true_type,
|
|
|
|
std::false_type >::type;
|
2022-04-29 21:40:02 +02:00
|
|
|
|
|
|
|
template<typename ObjectType, typename KeyType>
|
|
|
|
using detect_erase_with_key_type = decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
|
|
|
|
|
|
|
|
// type trait to check if object_t has an erase() member functions accepting KeyType
|
|
|
|
template<typename BasicJsonType, typename KeyType>
|
|
|
|
using has_erase_with_key_type = typename std::conditional <
|
|
|
|
is_detected <
|
|
|
|
detect_erase_with_key_type,
|
|
|
|
typename BasicJsonType::object_t, KeyType >::value,
|
|
|
|
std::true_type,
|
|
|
|
std::false_type >::type;
|
|
|
|
|
2021-08-22 20:30:20 +02:00
|
|
|
// a naive helper to check if a type is an ordered_map (exploits the fact that
|
|
|
|
// ordered_map inherits capacity() from std::vector)
|
|
|
|
template <typename T>
|
|
|
|
struct is_ordered_map
|
|
|
|
{
|
|
|
|
using one = char;
|
|
|
|
|
|
|
|
struct two
|
|
|
|
{
|
|
|
|
char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename C> static one test( decltype(&C::capacity) ) ;
|
|
|
|
template <typename C> static two test(...);
|
|
|
|
|
|
|
|
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
|
|
|
};
|
|
|
|
|
2021-07-30 14:48:25 +02:00
|
|
|
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
|
2021-07-30 15:20:22 +02:00
|
|
|
template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 >
|
2021-07-30 14:48:25 +02:00
|
|
|
T conditional_static_cast(U value)
|
|
|
|
{
|
|
|
|
return static_cast<T>(value);
|
|
|
|
}
|
|
|
|
|
2021-07-30 15:20:22 +02:00
|
|
|
template<typename T, typename U, enable_if_t<std::is_same<T, U>::value, int> = 0>
|
2021-07-30 14:48:25 +02:00
|
|
|
T conditional_static_cast(U value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2022-06-09 08:22:58 +02:00
|
|
|
template<typename... Types>
|
|
|
|
using all_integral = conjunction<std::is_integral<Types>...>;
|
|
|
|
|
|
|
|
template<typename... Types>
|
|
|
|
using all_signed = conjunction<std::is_signed<Types>...>;
|
|
|
|
|
|
|
|
template<typename... Types>
|
|
|
|
using all_unsigned = conjunction<std::is_unsigned<Types>...>;
|
|
|
|
|
|
|
|
// there's a disjunction trait in another PR; replace when merged
|
|
|
|
template<typename... Types>
|
|
|
|
using same_sign = std::integral_constant < bool,
|
|
|
|
all_signed<Types...>::value || all_unsigned<Types...>::value >;
|
|
|
|
|
|
|
|
template<typename OfType, typename T>
|
|
|
|
using never_out_of_range = std::integral_constant < bool,
|
|
|
|
(std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType)))
|
|
|
|
|| (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T)) >;
|
|
|
|
|
|
|
|
template<typename OfType, typename T,
|
|
|
|
bool OfTypeSigned = std::is_signed<OfType>::value,
|
|
|
|
bool TSigned = std::is_signed<T>::value>
|
|
|
|
struct value_in_range_of_impl2;
|
|
|
|
|
|
|
|
template<typename OfType, typename T>
|
|
|
|
struct value_in_range_of_impl2<OfType, T, false, false>
|
|
|
|
{
|
|
|
|
static constexpr bool test(T val)
|
|
|
|
{
|
|
|
|
using CommonType = typename std::common_type<OfType, T>::type;
|
2022-07-30 23:03:09 +02:00
|
|
|
return static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
|
2022-06-09 08:22:58 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename OfType, typename T>
|
|
|
|
struct value_in_range_of_impl2<OfType, T, true, false>
|
|
|
|
{
|
|
|
|
static constexpr bool test(T val)
|
|
|
|
{
|
|
|
|
using CommonType = typename std::common_type<OfType, T>::type;
|
2022-07-30 23:03:09 +02:00
|
|
|
return static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
|
2022-06-09 08:22:58 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename OfType, typename T>
|
|
|
|
struct value_in_range_of_impl2<OfType, T, false, true>
|
|
|
|
{
|
|
|
|
static constexpr bool test(T val)
|
|
|
|
{
|
|
|
|
using CommonType = typename std::common_type<OfType, T>::type;
|
2022-07-30 23:03:09 +02:00
|
|
|
return val >= 0 && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
|
2022-06-09 08:22:58 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename OfType, typename T>
|
|
|
|
struct value_in_range_of_impl2<OfType, T, true, true>
|
|
|
|
{
|
|
|
|
static constexpr bool test(T val)
|
|
|
|
{
|
|
|
|
using CommonType = typename std::common_type<OfType, T>::type;
|
2022-07-30 23:03:09 +02:00
|
|
|
return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)())
|
|
|
|
&& static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
|
2022-06-09 08:22:58 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename OfType, typename T,
|
|
|
|
bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
|
|
|
|
typename = detail::enable_if_t<all_integral<OfType, T>::value>>
|
|
|
|
struct value_in_range_of_impl1;
|
|
|
|
|
|
|
|
template<typename OfType, typename T>
|
|
|
|
struct value_in_range_of_impl1<OfType, T, false>
|
|
|
|
{
|
|
|
|
static constexpr bool test(T val)
|
|
|
|
{
|
|
|
|
return value_in_range_of_impl2<OfType, T>::test(val);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename OfType, typename T>
|
|
|
|
struct value_in_range_of_impl1<OfType, T, true>
|
|
|
|
{
|
|
|
|
static constexpr bool test(T /*val*/)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename OfType, typename T>
|
|
|
|
inline constexpr bool value_in_range_of(T val)
|
|
|
|
{
|
|
|
|
return value_in_range_of_impl1<OfType, T>::test(val);
|
|
|
|
}
|
|
|
|
|
2022-08-07 13:54:55 +02:00
|
|
|
template<bool Value>
|
|
|
|
using bool_constant = std::integral_constant<bool, Value>;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// is_c_string
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace impl
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline constexpr bool is_c_string()
|
|
|
|
{
|
|
|
|
using TUnExt = typename std::remove_extent<T>::type;
|
|
|
|
using TUnCVExt = typename std::remove_cv<TUnExt>::type;
|
|
|
|
using TUnPtr = typename std::remove_pointer<T>::type;
|
|
|
|
using TUnCVPtr = typename std::remove_cv<TUnPtr>::type;
|
|
|
|
return
|
|
|
|
(std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
|
|
|
|
|| (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
|
|
|
|
|
// checks whether T is a [cv] char */[cv] char[] C string
|
|
|
|
template<typename T>
|
|
|
|
struct is_c_string : bool_constant<impl::is_c_string<T>()> {};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using is_c_string_uncvref = is_c_string<uncvref_t<T>>;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// is_transparent
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace impl
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline constexpr bool is_transparent()
|
|
|
|
{
|
|
|
|
return is_detected<detect_is_transparent, T>::value;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
|
|
|
|
|
// checks whether T has a member named is_transparent
|
|
|
|
template<typename T>
|
|
|
|
struct is_transparent : bool_constant<impl::is_transparent<T>()> {};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-10-07 18:39:18 +02:00
|
|
|
} // namespace detail
|
2022-07-30 21:59:13 +02:00
|
|
|
NLOHMANN_JSON_NAMESPACE_END
|