From 2cac35c6adb1db3509b4b0b1c44cfefa964015ae Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 14 Oct 2026 17:47:38 +0200 Subject: [PATCH] Address review: conjunction/negation trait, astyle-friendly alias, docs table order Signed-off-by: Niels Lohmann --- .../docs/features/types/template_parameters.md | 4 ++-- include/nlohmann/detail/meta/type_traits.hpp | 16 +++++++--------- single_include/nlohmann/json.hpp | 16 +++++++--------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/docs/mkdocs/docs/features/types/template_parameters.md b/docs/mkdocs/docs/features/types/template_parameters.md index fe8b7495b..da0371281 100644 --- a/docs/mkdocs/docs/features/types/template_parameters.md +++ b/docs/mkdocs/docs/features/types/template_parameters.md @@ -542,9 +542,9 @@ therefore silently changes parse results rather than raising an error. See | `#!cpp std::int64_t` / `#!cpp std::uint64_t` (default) | full | | `#!cpp std::int32_t` / `#!cpp std::uint32_t`, `#!cpp long long` / `#!cpp unsigned long long` | full; narrower types change which literals the parser can represent | | any other pair of standard signed/unsigned integer types | full | -| class types, enumerations | not usable; `#!cpp std::is_integral` must hold | | the same signed integer type for both, e.g. `#!cpp std::int64_t` / `#!cpp std::int64_t` | full; every integer is stored as `number_integer_t`, see [above](#same-type-for-both) | -| `#!cpp bool`, or a type already used for another member of the union | not usable; `#!cpp std::is_integral` is in fact `#!cpp true`, but the `get_impl_ptr` overloads for `boolean_t`, `number_integer_t`, `number_unsigned_t` and `number_float_t` would collide | +| class types, enumerations | not usable; `#!cpp std::is_integral` must hold | +| `#!cpp bool`, `number_float_t`, or the type of another member of the union | not usable; `#!cpp std::is_integral` is in fact `#!cpp true`, but the `get_impl_ptr` overloads for `boolean_t`, `number_integer_t`, `number_unsigned_t` and `number_float_t` would collide | ## `NumberFloatType` diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 3fff8ac62..69741fad7 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -692,11 +692,11 @@ struct is_compatible_number_integer_type // if number_unsigned_t is the same type as number_integer_t, unsigned integers // are stored as number_integer as well (#2573) template -struct is_compatible_number_integer_type < BasicJsonType, CompatibleNumberIntegerType, - enable_if_t < std::is_same::value&& - std::is_integral::value&& - std::is_unsigned::value&& - !std::is_same::value >> +struct is_compatible_number_integer_type, + std::is_integral, + std::is_unsigned, + negation>>::value>> : std::is_constructible {}; template @@ -1047,10 +1047,8 @@ struct same_as_number_integer_type {}; // types through an incomplete basic_json (MSVC reports a recursive alias, and // old GCC versions crash) template -using number_unsigned_overload_type = typename std::conditional < - std::is_same::value, - same_as_number_integer_type, - NumberUnsignedType >::type; +using number_unsigned_overload_type = typename std::conditional::value, + same_as_number_integer_type, NumberUnsignedType>::type; // number_unsigned_t of BasicJsonType, or same_as_number_integer_type if it is // the same type as number_integer_t diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8191bbd19..a41ab71c6 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4696,11 +4696,11 @@ struct is_compatible_number_integer_type // if number_unsigned_t is the same type as number_integer_t, unsigned integers // are stored as number_integer as well (#2573) template -struct is_compatible_number_integer_type < BasicJsonType, CompatibleNumberIntegerType, - enable_if_t < std::is_same::value&& - std::is_integral::value&& - std::is_unsigned::value&& - !std::is_same::value >> +struct is_compatible_number_integer_type, + std::is_integral, + std::is_unsigned, + negation>>::value>> : std::is_constructible {}; template @@ -5051,10 +5051,8 @@ struct same_as_number_integer_type {}; // types through an incomplete basic_json (MSVC reports a recursive alias, and // old GCC versions crash) template -using number_unsigned_overload_type = typename std::conditional < - std::is_same::value, - same_as_number_integer_type, - NumberUnsignedType >::type; +using number_unsigned_overload_type = typename std::conditional::value, + same_as_number_integer_type, NumberUnsignedType>::type; // number_unsigned_t of BasicJsonType, or same_as_number_integer_type if it is // the same type as number_integer_t