From 548345cf8ce52d28592bebbf54aebee402a01cf3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 29 Apr 2020 17:29:44 +0100 Subject: [PATCH] Modified etl::delegate for better lambda support. Added etl::is_class to type_traits.h Added missing return statement in etl::move_iterator in 'operator =' Added upport for compilers that do not support LDBL_xxx macros --- include/etl/delegate.h | 7 ++-- .../etl/generators/type_traits_generator.h | 39 +++++++++++++++--- include/etl/iterator.h | 1 + include/etl/limits.h | 40 +++++++++++++------ include/etl/type_traits.h | 39 +++++++++++++++--- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 7 ++++ 9 files changed, 108 insertions(+), 31 deletions(-) diff --git a/include/etl/delegate.h b/include/etl/delegate.h index 2ff012a5..a13b3d5e 100644 --- a/include/etl/delegate.h +++ b/include/etl/delegate.h @@ -51,6 +51,7 @@ Original publication: https://www.codeproject.com/Articles/1170503/The-Impossibl #include "platform.h" #include "error_handler.h" #include "exception.h" +#include "type_traits.h" #if ETL_CPP11_SUPPORTED == 0 #error NOT SUPPORTED FOR C++03 OR BELOW @@ -107,7 +108,7 @@ namespace etl //************************************************************************* // Constructor from lambda or functor. //************************************************************************* - template + template ::value, void>::type> delegate(const TLambda& instance) { assign((void*)(&instance), lambda_stub); @@ -125,7 +126,7 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template + template ::value, void>::type> static delegate create(const TLambda& instance) { return delegate((void*)(&instance), lambda_stub); @@ -210,7 +211,7 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template + template ::value, void>::type> delegate& operator =(const TLambda& instance) { assign((void*)(&instance), lambda_stub); diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index b5b924d8..bcbe95c9 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -629,17 +629,17 @@ namespace etl //*************************************************************************** /// is_base_of template::value || etl::is_fundamental::value)> - struct is_base_of + typename TDerived, + const bool IsFundamental = (etl::is_fundamental::value || etl::is_fundamental::value)> + struct is_base_of { private: template struct dummy {}; - struct internal: TDerived, dummy{}; + struct internal: TDerived, dummy{}; - static TBase* check(TBase*); - template static char check(dummy*); + static TBase* check(TBase*); + template static char check(dummy*); public: @@ -658,6 +658,24 @@ namespace etl inline constexpr bool is_base_of_v = is_base_of::value; #endif + //*************************************************************************** + /// is_class + namespace private_type_traits + { + template char test(int T::*); // Match for classes. + + struct dummy { char c[2]; }; + template dummy test(...); // Match for non-classes. + } + + template + struct is_class : etl::integral_constant(0)) == 1U> {}; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool is_class_v = is_class::value; +#endif + //*************************************************************************** /// add_lvalue_reference template struct add_lvalue_reference { typedef T& type; }; @@ -1232,6 +1250,15 @@ namespace etl inline constexpr bool is_base_of_v = std::is_base_of_v; #endif + //*************************************************************************** + /// is_class + template struct is_class : std::is_class{}; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool is_class_v = is_class::value; +#endif + //*************************************************************************** /// add_lvalue_reference template struct add_lvalue_reference : std::add_lvalue_reference {}; diff --git a/include/etl/iterator.h b/include/etl/iterator.h index 0efb564c..b58690c5 100644 --- a/include/etl/iterator.h +++ b/include/etl/iterator.h @@ -461,6 +461,7 @@ namespace etl move_iterator& operator =(const move_iterator& itr) { current = itr.current; + return *this; } iterator_type base() const diff --git a/include/etl/limits.h b/include/etl/limits.h index c01c85f2..be3a8f95 100644 --- a/include/etl/limits.h +++ b/include/etl/limits.h @@ -70,6 +70,21 @@ SOFTWARE. #define ETL_HAS_NAN true #endif +#if !defined(LDBL_MIN) && defined(DBL_MIN) + // Looks like we don't have those macros defined. + // That probably means that 'long double' is the same size as 'double'. + #define LDBL_MIN DBL_MIN + #define LDBL_MAX DBL_MAX + #define LDBL_EPSILON DBL_EPSILON + #define HUGE_VALL HUGE_VAL + #define LDBL_MANT_DIG DBL_MANT_DIG + #define LDBL_DIG DBL_DIG + #define LDBL_MIN_EXP DBL_MIN_EXP + #define LDBL_MIN_10_EXP DBL_MIN_10_EXP + #define LDBL_MAX_EXP DBL_MAX_EXP + #define LDBL_MAX_10_EXP DBL_MAX_10_EXP +#endif + namespace etl { enum float_round_style @@ -516,13 +531,13 @@ namespace etl static float quiet_NaN() { return ETL_NANF; } static float signaling_NaN() { return ETL_NANF; } - static const int digits = FLT_MANT_DIG; - static const int digits10 = FLT_DIG; + static const int digits = FLT_MANT_DIG; + static const int digits10 = FLT_DIG; static const int max_digits10 = ETL_LOG10_OF_2(FLT_MANT_DIG) + 2; - static const int min_exponent = FLT_MIN_EXP; + static const int min_exponent = FLT_MIN_EXP; static const int min_exponent10 = FLT_MIN_10_EXP; - static const int max_exponent = FLT_MAX_EXP; + static const int max_exponent = FLT_MAX_EXP; static const int max_exponent10 = FLT_MAX_10_EXP; }; @@ -542,13 +557,13 @@ namespace etl static double quiet_NaN() { return ETL_NAN; } static double signaling_NaN() { return ETL_NAN; } - static const int digits = DBL_MANT_DIG; - static const int digits10 = DBL_DIG; + static const int digits = DBL_MANT_DIG; + static const int digits10 = DBL_DIG; static const int max_digits10 = ETL_LOG10_OF_2(DBL_MANT_DIG) + 2; - static const int min_exponent = DBL_MIN_EXP; + static const int min_exponent = DBL_MIN_EXP; static const int min_exponent10 = DBL_MIN_10_EXP; - static const int max_exponent = DBL_MAX_EXP; + static const int max_exponent = DBL_MAX_EXP; static const int max_exponent10 = DBL_MAX_10_EXP; }; @@ -568,14 +583,13 @@ namespace etl static long double quiet_NaN() { return ETL_NANL; } static long double signaling_NaN() { return ETL_NANL; } - - static const int digits = LDBL_MANT_DIG; - static const int digits10 = LDBL_DIG; + static const int digits = LDBL_MANT_DIG; + static const int digits10 = LDBL_DIG; static const int max_digits10 = ETL_LOG10_OF_2(LDBL_MANT_DIG) + 2; - static const int min_exponent = LDBL_MIN_EXP; + static const int min_exponent = LDBL_MIN_EXP; static const int min_exponent10 = LDBL_MIN_10_EXP; - static const int max_exponent = LDBL_MAX_EXP; + static const int max_exponent = LDBL_MAX_EXP; static const int max_exponent10 = LDBL_MAX_10_EXP; }; } diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 4d473b27..5fe2006a 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -617,17 +617,17 @@ namespace etl //*************************************************************************** /// is_base_of template::value || etl::is_fundamental::value)> - struct is_base_of + typename TDerived, + const bool IsFundamental = (etl::is_fundamental::value || etl::is_fundamental::value)> + struct is_base_of { private: template struct dummy {}; - struct internal: TDerived, dummy{}; + struct internal: TDerived, dummy{}; - static TBase* check(TBase*); - template static char check(dummy*); + static TBase* check(TBase*); + template static char check(dummy*); public: @@ -646,6 +646,24 @@ namespace etl inline constexpr bool is_base_of_v = is_base_of::value; #endif + //*************************************************************************** + /// is_class + namespace private_type_traits + { + template char test(int T::*); // Match for classes. + + struct dummy { char c[2]; }; + template dummy test(...); // Match for non-classes. + } + + template + struct is_class : etl::integral_constant(0)) == 1U> {}; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool is_class_v = is_class::value; +#endif + //*************************************************************************** /// add_lvalue_reference template struct add_lvalue_reference { typedef T& type; }; @@ -1220,6 +1238,15 @@ namespace etl inline constexpr bool is_base_of_v = std::is_base_of_v; #endif + //*************************************************************************** + /// is_class + template struct is_class : std::is_class{}; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool is_class_v = is_class::value; +#endif + //*************************************************************************** /// add_lvalue_reference template struct add_lvalue_reference : std::add_lvalue_reference {}; diff --git a/include/etl/version.h b/include/etl/version.h index 7451c5b9..e7731211 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 17 #define ETL_VERSION_MINOR 8 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_PATCH 3 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index af7cd999..da5ce6a1 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "17.8.2", + "version": "17.8.3", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 984602b6..80866984 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=17.8.2 +version=17.8.3 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 56de1110..cc5ebf76 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,10 @@ +=============================================================================== +17.8.3 +Modified etl::delegate for better lambda support. +Added etl::is_class to type_traits.h +Added missing return statement in etl::move_iterator in 'operator =' +Added upport for compilers that do not support LDBL_xxx macros + =============================================================================== 17.8.2 Added check for NAN, nan(), nanf() or nanl() support.