Skip to content

Commit

Permalink
Added support for cv-qualified types in is_unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed May 14, 2021
1 parent 5785ac5 commit faf7c37
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
28 changes: 28 additions & 0 deletions extras/tests/Misc/TypeTraits.cpp
Expand Up @@ -131,6 +131,34 @@ TEST_CASE("Polyfills/type_traits") {
CHECK(is_unsigned<float>::value == false);
CHECK(is_unsigned<double>::value == false);

CHECK(is_unsigned<const unsigned char>::value == true);
CHECK(is_unsigned<const unsigned int>::value == true);
CHECK(is_unsigned<const unsigned short>::value == true);
CHECK(is_unsigned<const unsigned long>::value == true);
CHECK(is_unsigned<const bool>::value == true);
CHECK(is_unsigned<const char>::value == false);
CHECK(is_unsigned<const float>::value == false);
CHECK(is_unsigned<const double>::value == false);

CHECK(is_unsigned<volatile unsigned char>::value == true);
CHECK(is_unsigned<volatile unsigned int>::value == true);
CHECK(is_unsigned<volatile unsigned short>::value == true);
CHECK(is_unsigned<volatile unsigned long>::value == true);
CHECK(is_unsigned<volatile bool>::value == true);
CHECK(is_unsigned<volatile char>::value == false);
CHECK(is_unsigned<volatile float>::value == false);
CHECK(is_unsigned<volatile double>::value == false);

CHECK(is_unsigned<const volatile unsigned char>::value == true);
CHECK(is_unsigned<const volatile unsigned int>::value == true);
CHECK(is_unsigned<const volatile unsigned short>::value == true);
CHECK(is_unsigned<const volatile unsigned long>::value == true);
CHECK(is_unsigned<const volatile bool>::value == true);
CHECK(is_unsigned<const volatile char>::value == false);
CHECK(is_unsigned<const volatile float>::value == false);
CHECK(is_unsigned<const volatile double>::value == false);
}

SECTION("is_floating_point") {
CHECK(is_floating_point<int>::value == false);
CHECK(is_floating_point<float>::value == true);
Expand Down
37 changes: 14 additions & 23 deletions src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp
Expand Up @@ -5,33 +5,24 @@
#pragma once

#include "integral_constant.hpp"
namespace ARDUINOJSON_NAMESPACE {

template <typename>
struct is_unsigned : false_type {};

template <>
struct is_unsigned<bool> : true_type {};

template <>
struct is_unsigned<unsigned char> : true_type {};
#include "is_same.hpp"
#include "remove_cv.hpp"

template <>
struct is_unsigned<unsigned short> : true_type {};

template <>
struct is_unsigned<unsigned int> : true_type {};

template <>
struct is_unsigned<unsigned long> : true_type {};
namespace ARDUINOJSON_NAMESPACE {

// clang-format off
template <typename T>
struct is_unsigned : integral_constant<bool,
is_same<typename remove_cv<T>::type, unsigned char>::value ||
is_same<typename remove_cv<T>::type, unsigned short>::value ||
is_same<typename remove_cv<T>::type, unsigned int>::value ||
is_same<typename remove_cv<T>::type, unsigned long>::value ||
#if ARDUINOJSON_HAS_INT64
template <>
struct is_unsigned<unsigned __int64> : true_type {};
is_same<typename remove_cv<T>::type, unsigned __int64>::value ||
#endif

#if ARDUINOJSON_HAS_LONG_LONG
template <>
struct is_unsigned<unsigned long long> : true_type {};
is_same<typename remove_cv<T>::type, unsigned long long>::value ||
#endif
is_same<typename remove_cv<T>::type, bool>::value> {};
// clang-format on
} // namespace ARDUINOJSON_NAMESPACE

0 comments on commit faf7c37

Please sign in to comment.