Reference tuple from json (#5016)

* Add reference handling to tuples

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>

* Remove template template type because pair isn't working

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>

* amalgamate std::tie changes

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>

* allow the elation of a move by removing the ref requirement

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>

* force all number_xxx_t to be interchangeable

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>

* Finally got amalgamate to work correctly

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>

* remove const version, add a test case for scrambled number representations.

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>

* Use the logical set of requirements instead of decltype because VS 2015 doesn't like it

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>

---------

Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
This commit is contained in:
EALePain authored and GitHub committed 2026-01-23 08:14:55 +01:00
1 parent deb4c4f69f
commit 25f48639c7
5 files changed
+291 -12

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
#pragma once
#include <nlohmann/detail/macro_scope.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
#ifdef JSON_HAS_CPP_17
template<bool... Booleans>
struct cxpr_or_impl : std::integral_constant < bool, (Booleans || ...) > {};
template<bool... Booleans>
struct cxpr_and_impl : std::integral_constant < bool, (Booleans &&...) > {};
#else
template<bool... Booleans>
struct cxpr_or_impl : std::false_type {};
template<bool... Booleans>
struct cxpr_or_impl<true, Booleans...> : std::true_type {};
template<bool... Booleans>
struct cxpr_or_impl<false, Booleans...> : cxpr_or_impl<Booleans...> {};
template<bool... Booleans>
struct cxpr_and_impl : std::true_type {};
template<bool... Booleans>
struct cxpr_and_impl<true, Booleans...> : cxpr_and_impl<Booleans...> {};
template<bool... Booleans>
struct cxpr_and_impl<false, Booleans...> : std::false_type {};
#endif
template<class Boolean>
struct cxpr_not : std::integral_constant < bool, !Boolean::value > {};
template<class... Booleans>
struct cxpr_or : cxpr_or_impl<Booleans::value...> {};
template<bool... Booleans>
struct cxpr_or_c : cxpr_or_impl<Booleans...> {};
template<class... Booleans>
struct cxpr_and : cxpr_and_impl<Booleans::value...> {};
template<bool... Booleans>
struct cxpr_and_c : cxpr_and_impl<Booleans...> {};
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END
@@ -559,6 +559,28 @@ template<typename BasicJsonType, typename CompatibleType>
struct is_compatible_type
: is_compatible_type_impl<BasicJsonType, CompatibleType> {};
template<typename BasicJsonType, typename CompatibleReferenceType>
struct is_compatible_reference_type_impl
{
using JsonType = uncvref_t<BasicJsonType>;
using CVType = typename std::remove_reference<CompatibleReferenceType>::type;
using Type = typename std::remove_cv<CVType>::type;
constexpr static bool value = std::is_reference<CompatibleReferenceType>::value &&
(!std::is_const<typename std::remove_reference<BasicJsonType>::type>::value || std::is_const<CVType>::value) &&
(std::is_same<typename JsonType::boolean_t, Type>::value ||
std::is_same<typename JsonType::number_float_t, Type>::value ||
std::is_same<typename JsonType::number_integer_t, Type>::value ||
std::is_same<typename JsonType::number_unsigned_t, Type>::value ||
std::is_same<typename JsonType::string_t, Type>::value ||
std::is_same<typename JsonType::binary_t, Type>::value ||
std::is_same<typename JsonType::object_t, Type>::value ||
std::is_same<typename JsonType::array_t, Type>::value);
};
template<typename BasicJsonType, typename CompatibleReferenceType>
struct is_compatible_reference_type
: is_compatible_reference_type_impl<BasicJsonType, CompatibleReferenceType> {};
template<typename T1, typename T2>
struct is_constructible_tuple : std::false_type {};