From afc0a29c2ca0a4b4d0a88de00fa73a0af31cff4f Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 25 Nov 2024 11:26:29 +0100 Subject: [PATCH] Polyfills: add `decay` --- extras/tests/Misc/TypeTraits.cpp | 9 +++++ src/ArduinoJson/Polyfills/type_traits.hpp | 1 + .../Polyfills/type_traits/decay.hpp | 33 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/ArduinoJson/Polyfills/type_traits/decay.hpp diff --git a/extras/tests/Misc/TypeTraits.cpp b/extras/tests/Misc/TypeTraits.cpp index 7beb4658..ce411378 100644 --- a/extras/tests/Misc/TypeTraits.cpp +++ b/extras/tests/Misc/TypeTraits.cpp @@ -211,6 +211,15 @@ TEST_CASE("Polyfills/type_traits") { CHECK(is_enum::value == false); CHECK(is_enum::value == false); } + + SECTION("decay") { + CHECK(is_same, int>::value); + CHECK(is_same, int>::value); + CHECK(is_same, int>::value); + CHECK(is_same, int*>::value); + CHECK(is_same, int*>::value); + CHECK(is_same, const char*>::value); + } } TEST_CASE("is_std_string") { diff --git a/src/ArduinoJson/Polyfills/type_traits.hpp b/src/ArduinoJson/Polyfills/type_traits.hpp index 3004695a..471d352c 100644 --- a/src/ArduinoJson/Polyfills/type_traits.hpp +++ b/src/ArduinoJson/Polyfills/type_traits.hpp @@ -5,6 +5,7 @@ #pragma once #include "type_traits/conditional.hpp" +#include "type_traits/decay.hpp" #include "type_traits/enable_if.hpp" #include "type_traits/function_traits.hpp" #include "type_traits/integral_constant.hpp" diff --git a/src/ArduinoJson/Polyfills/type_traits/decay.hpp b/src/ArduinoJson/Polyfills/type_traits/decay.hpp new file mode 100644 index 00000000..29b4b6ee --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits/decay.hpp @@ -0,0 +1,33 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2024, Benoit BLANCHON +// MIT License + +#pragma once + +#include // size_t + +#include + +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE + +template +struct decay { + using type = T; +}; + +template +struct decay : decay {}; + +template +struct decay : decay {}; + +template +struct decay : decay {}; + +template +struct decay : decay {}; + +template +using decay_t = typename decay::type; + +ARDUINOJSON_END_PRIVATE_NAMESPACE