From 23496a3abf082a0a6d26dba43783f1bc8c83c4da Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 13 Jul 2020 12:44:34 +0200 Subject: [PATCH] :loud_sound: add test for type traits --- include/nlohmann/detail/input/lexer.hpp | 5 +---- include/nlohmann/detail/meta/type_traits.hpp | 4 ++++ single_include/nlohmann/json.hpp | 10 ++++++---- test/src/unit-alt-number.cpp | 8 ++++++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index bdeb610cf..efc249d92 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace nlohmann { @@ -918,10 +919,6 @@ class lexer : public lexer_base f = std::strtold(str, endptr); } - template - struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) > - {}; - JSON_HEDLEY_NON_NULL(2) unsigned long long strtoull(const char* str, char** str_end, std::true_type) { diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 2da7b3635..6911270e8 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -327,6 +327,10 @@ template struct is_constructible_array_type : is_constructible_array_type_impl {}; +template +struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) > +{}; + template struct is_compatible_integer_type_impl : std::false_type {}; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 3530ebc3b..b6aefbafe 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3142,6 +3142,10 @@ template struct is_constructible_array_type : is_constructible_array_type_impl {}; +template +struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) > +{}; + template struct is_compatible_integer_type_impl : std::false_type {}; @@ -8118,6 +8122,8 @@ class binary_reader // #include +// #include + namespace nlohmann { @@ -9023,10 +9029,6 @@ class lexer : public lexer_base f = std::strtold(str, endptr); } - template - struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) > - {}; - JSON_HEDLEY_NON_NULL(2) unsigned long long strtoull(const char* str, char** str_end, std::true_type) { diff --git a/test/src/unit-alt-number.cpp b/test/src/unit-alt-number.cpp index eae50f141..ab528cfff 100644 --- a/test/src/unit-alt-number.cpp +++ b/test/src/unit-alt-number.cpp @@ -101,6 +101,14 @@ TEST_CASE("Alternative number types") // 128-bit arithmetic does not work with sanitizers #if defined(__SIZEOF_INT128__) && !defined(__SANITIZE_ADDRESS__) + SECTION("type traits") + { + CHECK(std::is_integral<__int128_t>::value); + CHECK(std::is_integral<__uint128_t>::value); + CHECK(std::numeric_limits<__int128_t>::is_integer); + CHECK(std::numeric_limits<__uint128_t>::is_integer); + } + SECTION("128 bit integers") { using json128 = nlohmann::basic_json;