diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2021-05-12 09:12:09 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2021-05-12 09:12:09 +0200 |
commit | 39895a677e5d370824e702cfe90ebc67737b8482 (patch) | |
tree | ff5b4cc9e373d33a795d50d9333e05549bd9f2b8 /include/lib/ArduinoJson/Polyfills/type_traits | |
parent | 42e7fdf01c3a5701bb51e93ad6c650c3dbbc5450 (diff) |
import ArduinoJson 6.18.0
Diffstat (limited to 'include/lib/ArduinoJson/Polyfills/type_traits')
20 files changed, 500 insertions, 0 deletions
diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/conditional.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/conditional.hpp new file mode 100644 index 0000000..e42d1bb --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/conditional.hpp @@ -0,0 +1,20 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +template <bool Condition, class TrueType, class FalseType> +struct conditional { + typedef TrueType type; +}; + +template <class TrueType, class FalseType> +struct conditional<false, TrueType, FalseType> { + typedef FalseType type; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/declval.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/declval.hpp new file mode 100644 index 0000000..8708112 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/declval.hpp @@ -0,0 +1,14 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +template <typename T> +T declval(); + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/enable_if.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/enable_if.hpp new file mode 100644 index 0000000..cc29b33 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/enable_if.hpp @@ -0,0 +1,19 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +// A meta-function that return the type T if Condition is true. +template <bool Condition, typename T = void> +struct enable_if {}; + +template <typename T> +struct enable_if<true, T> { + typedef T type; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/integral_constant.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/integral_constant.hpp new file mode 100644 index 0000000..b53d711 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/integral_constant.hpp @@ -0,0 +1,19 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +template <typename T, T v> +struct integral_constant { + static const T value = v; +}; + +typedef integral_constant<bool, true> true_type; +typedef integral_constant<bool, false> false_type; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_array.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_array.hpp new file mode 100644 index 0000000..ee739a7 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_array.hpp @@ -0,0 +1,21 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +#include <stddef.h> // size_t + +namespace ARDUINOJSON_NAMESPACE { + +template <typename T> +struct is_array : false_type {}; + +template <typename T> +struct is_array<T[]> : true_type {}; + +template <typename T, size_t N> +struct is_array<T[N]> : true_type {}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_base_of.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_base_of.hpp new file mode 100644 index 0000000..32b41cd --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_base_of.hpp @@ -0,0 +1,26 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +// A meta-function that returns true if Derived inherits from TBase is an +// integral type. +template <typename TBase, typename TDerived> +class is_base_of { + protected: // <- to avoid GCC's "all member functions in class are private" + typedef char Yes[1]; + typedef char No[2]; + + static Yes &probe(const TBase *); + static No &probe(...); + + public: + static const bool value = + sizeof(probe(reinterpret_cast<TDerived *>(0))) == sizeof(Yes); +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_class.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_class.hpp new file mode 100644 index 0000000..a3808f3 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_class.hpp @@ -0,0 +1,26 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "declval.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template <typename T> +struct is_class { + protected: // <- to avoid GCC's "all member functions in class are private" + typedef char Yes[1]; + typedef char No[2]; + + template <typename U> + static Yes &probe(void (U::*)(void)); + template <typename> + static No &probe(...); + + public: + static const bool value = sizeof(probe<T>(0)) == sizeof(Yes); +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_const.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_const.hpp new file mode 100644 index 0000000..32e758c --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_const.hpp @@ -0,0 +1,17 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "integral_constant.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +// A meta-function that return the type T without the const modifier +template <typename T> +struct is_const : false_type {}; + +template <typename T> +struct is_const<const T> : true_type {}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_convertible.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_convertible.hpp new file mode 100644 index 0000000..847525a --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_convertible.hpp @@ -0,0 +1,47 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "declval.hpp" + +#ifdef _MSC_VER +#pragma warning(push) +// conversion from 'T' to 'To', possible loss of data +#pragma warning(disable : 4244) +#endif + +// clang-format off +#ifdef __ICCARM__ +// Suppress IAR Compiler Warning[Pa093]: implicit conversion from floating point to integer +#pragma diag_suppress=Pa093 +#endif +// clang-format on + +namespace ARDUINOJSON_NAMESPACE { + +template <typename From, typename To> +struct is_convertible { + protected: // <- to avoid GCC's "all member functions in class are private" + typedef char Yes[1]; + typedef char No[2]; + + static Yes &probe(To); + static No &probe(...); + + public: + static const bool value = sizeof(probe(declval<From>())) == sizeof(Yes); +}; + +} // namespace ARDUINOJSON_NAMESPACE + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// clang-format off +#ifdef __ICCARM__ +#pragma diag_default=Pa093 +#endif +// clang-format on diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_enum.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_enum.hpp new file mode 100644 index 0000000..26aec1d --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_enum.hpp @@ -0,0 +1,22 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "is_class.hpp" +#include "is_convertible.hpp" +#include "is_floating_point.hpp" +#include "is_integral.hpp" +#include "is_same.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template <typename T> +struct is_enum { + static const bool value = is_convertible<T, int>::value && + !is_class<T>::value && !is_integral<T>::value && + !is_floating_point<T>::value; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp new file mode 100644 index 0000000..b7e9d3d --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp @@ -0,0 +1,19 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "integral_constant.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template <typename> +struct is_floating_point : false_type {}; + +template <> +struct is_floating_point<float> : true_type {}; + +template <> +struct is_floating_point<double> : true_type {}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_integral.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_integral.hpp new file mode 100644 index 0000000..26e895c --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_integral.hpp @@ -0,0 +1,33 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Configuration.hpp> +#include "is_same.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +// A meta-function that returns true if T is an integral type. +template <typename T> +struct is_integral { + static const bool value = + is_same<T, signed char>::value || is_same<T, unsigned char>::value || + is_same<T, signed short>::value || is_same<T, unsigned short>::value || + is_same<T, signed int>::value || is_same<T, unsigned int>::value || + is_same<T, signed long>::value || is_same<T, unsigned long>::value || +#if ARDUINOJSON_HAS_LONG_LONG + is_same<T, signed long long>::value || + is_same<T, unsigned long long>::value || +#endif +#if ARDUINOJSON_HAS_INT64 + is_same<T, signed __int64>::value || + is_same<T, unsigned __int64>::value || +#endif + is_same<T, char>::value || is_same<T, bool>::value; +}; + +template <typename T> +struct is_integral<const T> : is_integral<T> {}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_pointer.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_pointer.hpp new file mode 100644 index 0000000..a249539 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_pointer.hpp @@ -0,0 +1,16 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "integral_constant.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template <typename T> +struct is_pointer : false_type {}; + +template <typename T> +struct is_pointer<T*> : true_type {}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_same.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_same.hpp new file mode 100644 index 0000000..db5da9b --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_same.hpp @@ -0,0 +1,17 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "integral_constant.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +// A meta-function that returns true if types T and U are the same. +template <typename T, typename U> +struct is_same : false_type {}; + +template <typename T> +struct is_same<T, T> : true_type {}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_signed.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_signed.hpp new file mode 100644 index 0000000..fbb701c --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_signed.hpp @@ -0,0 +1,43 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "integral_constant.hpp" +namespace ARDUINOJSON_NAMESPACE { + +template <typename> +struct is_signed : false_type {}; + +template <> +struct is_signed<char> : true_type {}; + +template <> +struct is_signed<signed char> : true_type {}; + +template <> +struct is_signed<signed short> : true_type {}; + +template <> +struct is_signed<signed int> : true_type {}; + +template <> +struct is_signed<signed long> : true_type {}; + +template <> +struct is_signed<float> : true_type {}; + +template <> +struct is_signed<double> : true_type {}; + +#if ARDUINOJSON_HAS_LONG_LONG +template <> +struct is_signed<signed long long> : true_type {}; +#endif + +#if ARDUINOJSON_HAS_INT64 +template <> +struct is_signed<signed __int64> : true_type {}; +#endif +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp new file mode 100644 index 0000000..be26498 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp @@ -0,0 +1,37 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#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 {}; + +template <> +struct is_unsigned<unsigned short> : true_type {}; + +template <> +struct is_unsigned<unsigned int> : true_type {}; + +template <> +struct is_unsigned<unsigned long> : true_type {}; + +#if ARDUINOJSON_HAS_INT64 +template <> +struct is_unsigned<unsigned __int64> : true_type {}; +#endif + +#if ARDUINOJSON_HAS_LONG_LONG +template <> +struct is_unsigned<unsigned long long> : true_type {}; +#endif +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/make_unsigned.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/make_unsigned.hpp new file mode 100644 index 0000000..4cf2d08 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/make_unsigned.hpp @@ -0,0 +1,49 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "type_identity.hpp" +namespace ARDUINOJSON_NAMESPACE { + +template <typename T> +struct make_unsigned; + +template <> +struct make_unsigned<char> : type_identity<unsigned char> {}; + +template <> +struct make_unsigned<signed char> : type_identity<unsigned char> {}; +template <> +struct make_unsigned<unsigned char> : type_identity<unsigned char> {}; + +template <> +struct make_unsigned<signed short> : type_identity<unsigned short> {}; +template <> +struct make_unsigned<unsigned short> : type_identity<unsigned short> {}; + +template <> +struct make_unsigned<signed int> : type_identity<unsigned int> {}; +template <> +struct make_unsigned<unsigned int> : type_identity<unsigned int> {}; + +template <> +struct make_unsigned<signed long> : type_identity<unsigned long> {}; +template <> +struct make_unsigned<unsigned long> : type_identity<unsigned long> {}; + +#if ARDUINOJSON_HAS_LONG_LONG +template <> +struct make_unsigned<signed long long> : type_identity<unsigned long long> {}; +template <> +struct make_unsigned<unsigned long long> : type_identity<unsigned long long> {}; +#endif + +#if ARDUINOJSON_HAS_INT64 +template <> +struct make_unsigned<signed __int64> : type_identity<unsigned __int64> {}; +template <> +struct make_unsigned<unsigned __int64> : type_identity<unsigned __int64> {}; +#endif +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/remove_const.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/remove_const.hpp new file mode 100644 index 0000000..5a19eb1 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/remove_const.hpp @@ -0,0 +1,20 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +// A meta-function that return the type T without the const modifier +template <typename T> +struct remove_const { + typedef T type; +}; +template <typename T> +struct remove_const<const T> { + typedef T type; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/remove_reference.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/remove_reference.hpp new file mode 100644 index 0000000..1812850 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/remove_reference.hpp @@ -0,0 +1,20 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Namespace.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +// A meta-function that return the type T without the reference modifier. +template <typename T> +struct remove_reference { + typedef T type; +}; +template <typename T> +struct remove_reference<T&> { + typedef T type; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Polyfills/type_traits/type_identity.hpp b/include/lib/ArduinoJson/Polyfills/type_traits/type_identity.hpp new file mode 100644 index 0000000..c464a47 --- /dev/null +++ b/include/lib/ArduinoJson/Polyfills/type_traits/type_identity.hpp @@ -0,0 +1,15 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "integral_constant.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template <typename T> +struct type_identity { + typedef T type; +}; +} // namespace ARDUINOJSON_NAMESPACE |