From b45012fcf3ed759f3e98e7c4483156517672de00 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 7 Nov 2026 10:12:50 +0100 Subject: [PATCH] Iterator ranges: astyle-safe trait members; reserve in the test helper The byte check and the container match are static constexpr members instead of integral_constant arguments and a default template argument with comparisons, which astyle spaced out. Signed-off-by: Niels Lohmann --- .../nlohmann/detail/input/input_adapters.hpp | 21 +++++++++++++------ single_include/nlohmann/json.hpp | 21 +++++++++++++------ tests/src/unit-deserialization.cpp | 1 + 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 3acf66c54..0775ed442 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -1186,17 +1186,26 @@ other iterator can be mistaken for one. (std::basic_string is only matched for char: other character types need std::char_traits specializations that the standard library need not have.) */ -template < typename IteratorType, typename CharType, bool IsByte = sizeof(CharType) == 1 && std::is_integral::value && !std::is_same::value > +template +struct is_byte_char_type +{ + // a member, not an integral_constant argument, which astyle misformats + static constexpr bool value = sizeof(CharType) == 1 && std::is_integral::value && !std::is_same::value; +}; + +template::value> struct is_std_contiguous_byte_iterator_impl : std::false_type {}; // (the containers are only named for byte types) template struct is_std_contiguous_byte_iterator_impl - : std::integral_constant < bool, !std::is_pointer::value - && (std::is_same::iterator>::value - || std::is_same::const_iterator>::value - || std::is_same::value - || std::is_same::value) > {}; +{ + static constexpr bool value = !std::is_pointer::value + && (std::is_same::iterator>::value + || std::is_same::const_iterator>::value + || std::is_same::value + || std::is_same::value); +}; template struct is_std_contiguous_byte_iterator diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a4da8f409..4ed4bede1 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -10295,17 +10295,26 @@ other iterator can be mistaken for one. (std::basic_string is only matched for char: other character types need std::char_traits specializations that the standard library need not have.) */ -template < typename IteratorType, typename CharType, bool IsByte = sizeof(CharType) == 1 && std::is_integral::value && !std::is_same::value > +template +struct is_byte_char_type +{ + // a member, not an integral_constant argument, which astyle misformats + static constexpr bool value = sizeof(CharType) == 1 && std::is_integral::value && !std::is_same::value; +}; + +template::value> struct is_std_contiguous_byte_iterator_impl : std::false_type {}; // (the containers are only named for byte types) template struct is_std_contiguous_byte_iterator_impl - : std::integral_constant < bool, !std::is_pointer::value - && (std::is_same::iterator>::value - || std::is_same::const_iterator>::value - || std::is_same::value - || std::is_same::value) > {}; +{ + static constexpr bool value = !std::is_pointer::value + && (std::is_same::iterator>::value + || std::is_same::const_iterator>::value + || std::is_same::value + || std::is_same::value); +}; template struct is_std_contiguous_byte_iterator diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index ec94678c0..858597cdc 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp @@ -1433,6 +1433,7 @@ template std::vector bytes_as(const std::string& text) { std::vector result; + result.reserve(text.size()); for (const char c : text) { result.push_back(static_cast(c));