mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 17:06:05 +08:00
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
This commit is contained in:
parent
ace78898f2
commit
548345cf8c
@ -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 <typename TLambda>
|
||||
template <typename TLambda, typename = typename etl::enable_if<etl::is_class<TLambda>::value, void>::type>
|
||||
delegate(const TLambda& instance)
|
||||
{
|
||||
assign((void*)(&instance), lambda_stub<TLambda>);
|
||||
@ -125,7 +126,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Create from Lambda or Functor.
|
||||
//*************************************************************************
|
||||
template <typename TLambda>
|
||||
template <typename TLambda, typename = typename etl::enable_if<etl::is_class<TLambda>::value, void>::type>
|
||||
static delegate create(const TLambda& instance)
|
||||
{
|
||||
return delegate((void*)(&instance), lambda_stub<TLambda>);
|
||||
@ -210,7 +211,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Create from Lambda or Functor.
|
||||
//*************************************************************************
|
||||
template <typename TLambda>
|
||||
template <typename TLambda, typename = typename etl::enable_if<etl::is_class<TLambda>::value, void>::type>
|
||||
delegate& operator =(const TLambda& instance)
|
||||
{
|
||||
assign((void*)(&instance), lambda_stub<TLambda>);
|
||||
|
||||
@ -629,17 +629,17 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// is_base_of
|
||||
template<typename TBase,
|
||||
typename TDerived,
|
||||
const bool IsFundamental = (etl::is_fundamental<TBase>::value || etl::is_fundamental<TDerived>::value)>
|
||||
struct is_base_of
|
||||
typename TDerived,
|
||||
const bool IsFundamental = (etl::is_fundamental<TBase>::value || etl::is_fundamental<TDerived>::value)>
|
||||
struct is_base_of
|
||||
{
|
||||
private:
|
||||
|
||||
template<typename T> struct dummy {};
|
||||
struct internal: TDerived, dummy<int>{};
|
||||
struct internal: TDerived, dummy<int>{};
|
||||
|
||||
static TBase* check(TBase*);
|
||||
template<typename T> static char check(dummy<T>*);
|
||||
static TBase* check(TBase*);
|
||||
template<typename T> static char check(dummy<T>*);
|
||||
|
||||
public:
|
||||
|
||||
@ -658,6 +658,24 @@ namespace etl
|
||||
inline constexpr bool is_base_of_v = is_base_of<T1, T2>::value;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_class
|
||||
namespace private_type_traits
|
||||
{
|
||||
template <typename T> char test(int T::*); // Match for classes.
|
||||
|
||||
struct dummy { char c[2]; };
|
||||
template <typename T> dummy test(...); // Match for non-classes.
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct is_class : etl::integral_constant<bool, sizeof(private_type_traits::test<T>(0)) == 1U> {};
|
||||
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename T>
|
||||
inline constexpr bool is_class_v = is_class<T>::value;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// add_lvalue_reference
|
||||
template <typename T> 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<TBase, TDerived>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_class
|
||||
template <typename T> struct is_class : std::is_class<T>{};
|
||||
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename T>
|
||||
inline constexpr bool is_class_v = is_class<T>::value;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// add_lvalue_reference
|
||||
template <typename T> struct add_lvalue_reference : std::add_lvalue_reference<T> {};
|
||||
|
||||
@ -461,6 +461,7 @@ namespace etl
|
||||
move_iterator& operator =(const move_iterator<U>& itr)
|
||||
{
|
||||
current = itr.current;
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator_type base() const
|
||||
|
||||
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@ -617,17 +617,17 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// is_base_of
|
||||
template<typename TBase,
|
||||
typename TDerived,
|
||||
const bool IsFundamental = (etl::is_fundamental<TBase>::value || etl::is_fundamental<TDerived>::value)>
|
||||
struct is_base_of
|
||||
typename TDerived,
|
||||
const bool IsFundamental = (etl::is_fundamental<TBase>::value || etl::is_fundamental<TDerived>::value)>
|
||||
struct is_base_of
|
||||
{
|
||||
private:
|
||||
|
||||
template<typename T> struct dummy {};
|
||||
struct internal: TDerived, dummy<int>{};
|
||||
struct internal: TDerived, dummy<int>{};
|
||||
|
||||
static TBase* check(TBase*);
|
||||
template<typename T> static char check(dummy<T>*);
|
||||
static TBase* check(TBase*);
|
||||
template<typename T> static char check(dummy<T>*);
|
||||
|
||||
public:
|
||||
|
||||
@ -646,6 +646,24 @@ namespace etl
|
||||
inline constexpr bool is_base_of_v = is_base_of<T1, T2>::value;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_class
|
||||
namespace private_type_traits
|
||||
{
|
||||
template <typename T> char test(int T::*); // Match for classes.
|
||||
|
||||
struct dummy { char c[2]; };
|
||||
template <typename T> dummy test(...); // Match for non-classes.
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct is_class : etl::integral_constant<bool, sizeof(private_type_traits::test<T>(0)) == 1U> {};
|
||||
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename T>
|
||||
inline constexpr bool is_class_v = is_class<T>::value;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// add_lvalue_reference
|
||||
template <typename T> 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<TBase, TDerived>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_class
|
||||
template <typename T> struct is_class : std::is_class<T>{};
|
||||
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename T>
|
||||
inline constexpr bool is_class_v = is_class<T>::value;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// add_lvalue_reference
|
||||
template <typename T> struct add_lvalue_reference : std::add_lvalue_reference<T> {};
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library
|
||||
version=17.8.2
|
||||
version=17.8.3
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user