Polyfills: add decay

This commit is contained in:
Benoit Blanchon
2024-11-25 11:26:29 +01:00
parent a256ec7fff
commit afc0a29c2c
3 changed files with 43 additions and 0 deletions

View File

@ -211,6 +211,15 @@ TEST_CASE("Polyfills/type_traits") {
CHECK(is_enum<bool>::value == false);
CHECK(is_enum<double>::value == false);
}
SECTION("decay") {
CHECK(is_same<decay_t<int>, int>::value);
CHECK(is_same<decay_t<int&>, int>::value);
CHECK(is_same<decay_t<int&&>, int>::value);
CHECK(is_same<decay_t<int[]>, int*>::value);
CHECK(is_same<decay_t<int[10]>, int*>::value);
CHECK(is_same<decay_t<decltype("toto")>, const char*>::value);
}
}
TEST_CASE("is_std_string") {

View File

@ -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"

View File

@ -0,0 +1,33 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License
#pragma once
#include <stddef.h> // size_t
#include <ArduinoJson/Namespace.hpp>
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
template <typename T>
struct decay {
using type = T;
};
template <typename T>
struct decay<T&> : decay<T> {};
template <typename T>
struct decay<T&&> : decay<T> {};
template <typename T>
struct decay<T[]> : decay<T*> {};
template <typename T, size_t N>
struct decay<T[N]> : decay<T*> {};
template <typename T>
using decay_t = typename decay<T>::type;
ARDUINOJSON_END_PRIVATE_NAMESPACE