mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-06-25 01:11:35 +02:00
Polyfills: add decay
This commit is contained in:
@ -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") {
|
||||
|
@ -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"
|
||||
|
33
src/ArduinoJson/Polyfills/type_traits/decay.hpp
Normal file
33
src/ArduinoJson/Polyfills/type_traits/decay.hpp
Normal 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
|
Reference in New Issue
Block a user