From fefa98702cb871ddcb26f1995ac9e01eacbb5662 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Mon, 11 Jul 2022 21:30:23 +0000 Subject: [PATCH] roll back some parts of the change --- include/nlohmann/detail/output/serializer.hpp | 13 ++++++------ tests/src/unit-custom-integer.cpp | 20 ++++++------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index dc8a5ab50..418bccd45 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -678,7 +678,7 @@ class serializer template ::is_signed, int> = 0> bool is_negative_number(NumberType x) { - return x < NumberType(0); + return x < 0; } template < typename NumberType, enable_if_t < !std::numeric_limits::is_signed, int > = 0 > @@ -721,7 +721,7 @@ class serializer }; // special case for "0" - if (x == NumberType(0)) + if (x == 0) { o->write_character('0'); return; @@ -757,16 +757,15 @@ class serializer // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu // See: https://www.youtube.com/watch?v=o4-CwDo2zpg - const NumberType hundred = 100; - while (abs_value >= hundred) + while (abs_value >= 100) { - const auto digits_index = static_cast((abs_value % hundred)); - abs_value /= hundred; + const auto digits_index = static_cast((abs_value % 100)); + abs_value /= 100; *(--buffer_ptr) = digits_to_99[digits_index][1]; *(--buffer_ptr) = digits_to_99[digits_index][0]; } - if (abs_value >= NumberType(10)) + if (abs_value >= 10) { const auto digits_index = static_cast(abs_value); *(--buffer_ptr) = digits_to_99[digits_index][1]; diff --git a/tests/src/unit-custom-integer.cpp b/tests/src/unit-custom-integer.cpp index 0e3baf440..bcf6fa398 100644 --- a/tests/src/unit-custom-integer.cpp +++ b/tests/src/unit-custom-integer.cpp @@ -43,7 +43,7 @@ class wrapped_int return val; } wrapped_int() = default; - wrapped_int(T val) : val(val) {} + /* implicit */ wrapped_int(T val) : val(val) {} bool operator==(const wrapped_int& other) const { @@ -59,37 +59,29 @@ class wrapped_int } bool operator%(const wrapped_int& other) const { - return static_cast(*this) % static_cast(other.val); + return static_cast(*this) % static_cast(other); } wrapped_int& operator/=(const wrapped_int& other) { - if (val != nullptr) - { - *val /= static_cast(other.val); - } + val /= static_cast(other); return *this; } bool operator<(const wrapped_int& other) const { - return static_cast(*this) < static_cast(other.val); + return static_cast(*this) < static_cast(other); } bool operator<=(const wrapped_int& other) const { - return static_cast(*this) <= static_cast(other.val); - } - - friend void swap(wrapped_int& self, wrapped_int& other) - { - swap(self.val, other.val); + return static_cast(*this) <= static_cast(other); } }; template class std::numeric_limits> { public: + static constexpr bool is_specialized = std::numeric_limits::is_specialized; static constexpr bool is_signed = std::numeric_limits::is_signed; static constexpr bool is_integer = std::numeric_limits::is_integer; - static constexpr bool is_specialized = std::numeric_limits::is_specialized; }; TEST_CASE("custom integer types")