From 6144794221fb7cb2fe3ee0cc48244f0aed869ea9 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 30 Nov 2020 12:56:46 +0000 Subject: [PATCH] constexpr, template aliases and inline variables --- include/etl/absolute.h | 4 +- include/etl/combinations.h | 7 +- include/etl/delegate.h | 22 +- include/etl/factorial.h | 9 +- include/etl/fibonacci.h | 11 +- .../etl/generators/type_traits_generator.h | 2 +- include/etl/largest.h | 38 +++ include/etl/limits.h | 232 ++++++++-------- include/etl/log.h | 21 +- include/etl/negative.h | 4 +- include/etl/permutations.h | 9 +- include/etl/platform.h | 2 + include/etl/power.h | 30 +- include/etl/ratio.h | 4 +- include/etl/smallest.h | 37 ++- include/etl/sqrt.h | 7 +- include/etl/type_lookup.h | 6 +- include/etl/type_select.h | 2 + test/test_alignment.cpp | 2 +- test/test_delegate.cpp | 259 ++++++++++++++++++ test/test_largest.cpp | 104 +++++++ test/test_smallest.cpp | 207 ++++++++++++++ test/test_type_lookup.cpp | 119 ++++++++ test/test_type_select.cpp | 71 ++++- 24 files changed, 1051 insertions(+), 158 deletions(-) diff --git a/include/etl/absolute.h b/include/etl/absolute.h index 165dba9c..d473b3ec 100644 --- a/include/etl/absolute.h +++ b/include/etl/absolute.h @@ -39,7 +39,7 @@ namespace etl // For signed types. //*************************************************************************** template - typename etl::enable_if::value, T>::type + ETL_CONSTEXPR typename etl::enable_if::value, T>::type absolute(T value) { return (value < T(0)) ? -value : value; @@ -49,7 +49,7 @@ namespace etl // For unsigned types. //*************************************************************************** template - typename etl::enable_if::value, T>::type + ETL_CONSTEXPR typename etl::enable_if::value, T>::type absolute(T value) { return value; diff --git a/include/etl/combinations.h b/include/etl/combinations.h index ef868471..89a25f52 100644 --- a/include/etl/combinations.h +++ b/include/etl/combinations.h @@ -48,8 +48,13 @@ namespace etl template struct combinations { - static const size_t value = etl::permutations::value / etl::factorial::value; + static ETL_CONSTANT size_t value = etl::permutations::value / etl::factorial::value; }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t combinations_v = combinations::value; +#endif } #endif diff --git a/include/etl/delegate.h b/include/etl/delegate.h index a13b3d5e..47716c54 100644 --- a/include/etl/delegate.h +++ b/include/etl/delegate.h @@ -118,7 +118,7 @@ namespace etl /// Create from function (Compile time). //************************************************************************* template - static delegate create() + ETL_CONSTEXPR14 static delegate create() { return delegate(ETL_NULLPTR, function_stub); } @@ -127,7 +127,7 @@ namespace etl /// Create from Lambda or Functor. //************************************************************************* template ::value, void>::type> - static delegate create(const TLambda& instance) + ETL_CONSTEXPR14 static delegate create(const TLambda& instance) { return delegate((void*)(&instance), lambda_stub); } @@ -136,7 +136,7 @@ namespace etl /// Create from instance method (Run time). //************************************************************************* template - static delegate create(T& instance) + ETL_CONSTEXPR14 static delegate create(T& instance) { return delegate((void*)(&instance), method_stub); } @@ -152,7 +152,7 @@ namespace etl /// Create from const instance method (Run time). //************************************************************************* template - static delegate create(const T& instance) + ETL_CONSTEXPR14 static delegate create(const T& instance) { return delegate((void*)(&instance), const_method_stub); } @@ -161,13 +161,13 @@ namespace etl /// Disable create from rvalue instance method (Run time). //************************************************************************* template - static delegate create(T&& instance) = delete; + ETL_CONSTEXPR14 static delegate create(T&& instance) = delete; //************************************************************************* /// Create from instance method (Compile time). //************************************************************************* template - static delegate create() + ETL_CONSTEXPR14 static delegate create() { return delegate(method_instance_stub); } @@ -176,7 +176,7 @@ namespace etl /// Create from const instance method (Compile time). //************************************************************************* template - static delegate create() + ETL_CONSTEXPR14 static delegate create() { return delegate(const_method_instance_stub); } @@ -187,7 +187,7 @@ namespace etl /// At the time of writing, GCC appears to have trouble with this. //************************************************************************* template - static delegate create() + ETL_CONSTEXPR14 static delegate create() { return delegate(operator_instance_stub); } @@ -288,7 +288,7 @@ namespace etl //************************************************************************* /// Constructs a delegate from an object and stub. //************************************************************************* - delegate(void* object, stub_type stub) + ETL_CONSTEXPR14 delegate(void* object, stub_type stub) { invocation.object = object; invocation.stub = stub; @@ -297,7 +297,7 @@ namespace etl //************************************************************************* /// Constructs a delegate from a stub. //************************************************************************* - delegate(stub_type stub) + ETL_CONSTEXPR14 delegate(stub_type stub) { invocation.object = ETL_NULLPTR; invocation.stub = stub; @@ -306,7 +306,7 @@ namespace etl //************************************************************************* /// Assign from an object and stub. //************************************************************************* - void assign(void* object, stub_type stub) + ETL_CONSTEXPR14 void assign(void* object, stub_type stub) { invocation.object = object; invocation.stub = stub; diff --git a/include/etl/factorial.h b/include/etl/factorial.h index 1767caa5..15070f0a 100644 --- a/include/etl/factorial.h +++ b/include/etl/factorial.h @@ -49,7 +49,7 @@ namespace etl template struct factorial { - static const size_t value = N * factorial::value; + static ETL_CONSTANT size_t value = N * factorial::value; }; //*************************************************************************** @@ -58,8 +58,13 @@ namespace etl template <> struct factorial<0> { - static const size_t value = 1; + static ETL_CONSTANT size_t value = 1; }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t factorial_v = factorial::value; +#endif } #endif diff --git a/include/etl/fibonacci.h b/include/etl/fibonacci.h index fd351890..f4d00de7 100644 --- a/include/etl/fibonacci.h +++ b/include/etl/fibonacci.h @@ -49,7 +49,7 @@ namespace etl template struct fibonacci { - static const size_t value = fibonacci::value + fibonacci::value; + static ETL_CONSTANT size_t value = fibonacci::value + fibonacci::value; }; //*************************************************************************** @@ -58,7 +58,7 @@ namespace etl template <> struct fibonacci<1> { - static const size_t value = 1; + static ETL_CONSTANT size_t value = 1; }; //*************************************************************************** @@ -67,8 +67,13 @@ namespace etl template <> struct fibonacci<0> { - static const size_t value = 0; + static ETL_CONSTANT size_t value = 0; }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t fibonacci_v = fibonacci::value; +#endif } #endif diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 0be7dfa7..200e267a 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -770,7 +770,7 @@ namespace etl /// These require compiler specific intrinsics. #if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5) template struct alignment_of : integral_constant { }; -#elif ETL_COMPILER_MICROSOFT +#elif defined(ETL_COMPILER_MICROSOFT) template struct alignment_of : integral_constant {}; #elif defined(ETL_COMPILER_IAR) || defined(ETL_COMPILER_TI) template struct alignment_of : integral_constant {}; diff --git a/include/etl/largest.h b/include/etl/largest.h index 5880d907..98578ee1 100644 --- a/include/etl/largest.h +++ b/include/etl/largest.h @@ -109,6 +109,17 @@ namespace etl size = etl::size_of::value }; }; + +#if ETL_CPP14_SUPPORTED + template + using largest_type_t = typename largest_type::type; +#endif + +#if ETL_CPP17_SUPPORTED + template + constexpr size_t largest_type_v = largest_type::size; +#endif + #else //*************************************************************************** /// Template to determine the largest type and size. @@ -195,6 +206,12 @@ namespace etl value = etl::alignment_of::value }; }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t largest_alignment_v = largest_alignment::value; +#endif + #else //*************************************************************************** /// Template to determine the largest alignment. @@ -254,6 +271,11 @@ namespace etl typedef typename etl::smallest_int_for_bits::type>::bits + 1>::type type; }; +#if ETL_CPP14_SUPPORTED + template + using larger_int_type_t = typename larger_int_type::type; +#endif + //*************************************************************************** /// Defines a type that is as larger or larger than the specified type. /// Will return the specified type is there is not a larger type. @@ -267,6 +289,11 @@ namespace etl typedef typename etl::smallest_uint_for_bits::type>::bits + 1>::type type; }; +#if ETL_CPP14_SUPPORTED + template + using larger_uint_type_t = typename larger_uint_type::type; +#endif + //*************************************************************************** /// Defines a type that is as larger or larger than the specified type. /// Will return the specified type is there is not a larger type. @@ -292,6 +319,11 @@ namespace etl typedef typename etl::smallest_int_for_bits::bits + 1>::type type; }; +#if ETL_CPP14_SUPPORTED + template + using larger_type_t = typename larger_type::type; +#endif + #if ETL_CPP11_SUPPORTED && !defined(ETL_LARGEST_FORCE_CPP03) //*************************************************************************** /// Template to determine the largest type, size and alignment. @@ -309,6 +341,12 @@ namespace etl alignment = etl::largest_alignment::value }; }; + +#if ETL_CPP14_SUPPORTED + template + using largest_t = typename largest::type; +#endif + #else //*************************************************************************** /// Template to determine the largest type, size and alignment. diff --git a/include/etl/limits.h b/include/etl/limits.h index 2d58e354..8268ca6b 100644 --- a/include/etl/limits.h +++ b/include/etl/limits.h @@ -125,47 +125,47 @@ namespace etl { public: - static const bool is_specialized = true; - static const bool is_integer = true; - static const bool is_exact = true; - static const int max_digits10 = 0; - static const int radix = 2; - static const int min_exponent = 0; - static const int min_exponent10 = 0; - static const int max_exponent = 0; - static const int max_exponent10 = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool has_denorm_loss = false; - static const bool is_iec559 = false; - static const bool is_bounded = true; - static const bool traps = false; - static const bool tinyness_before = false; - static const float_denorm_style has_denorm = denorm_absent; - static const float_round_style round_style = round_toward_zero; + static ETL_CONSTANT bool is_specialized = true; + static ETL_CONSTANT bool is_integer = true; + static ETL_CONSTANT bool is_exact = true; + static ETL_CONSTANT int max_digits10 = 0; + static ETL_CONSTANT int radix = 2; + static ETL_CONSTANT int min_exponent = 0; + static ETL_CONSTANT int min_exponent10 = 0; + static ETL_CONSTANT int max_exponent = 0; + static ETL_CONSTANT int max_exponent10 = 0; + static ETL_CONSTANT bool has_infinity = false; + static ETL_CONSTANT bool has_quiet_NaN = false; + static ETL_CONSTANT bool has_signaling_NaN = false; + static ETL_CONSTANT bool has_denorm_loss = false; + static ETL_CONSTANT bool is_iec559 = false; + static ETL_CONSTANT bool is_bounded = true; + static ETL_CONSTANT bool traps = false; + static ETL_CONSTANT bool tinyness_before = false; + static ETL_CONSTANT float_denorm_style has_denorm = denorm_absent; + static ETL_CONSTANT float_round_style round_style = round_toward_zero; }; class etl_floating_point_limits { public: - static const bool is_specialized = true; - static const bool is_signed = true; - static const bool is_integer = false; - static const bool is_exact = false; - static const int radix = 2; - static const bool has_infinity = true; - static const bool has_quiet_NaN = ETL_HAS_NAN; - static const bool has_signaling_NaN = ETL_HAS_NAN; - static const bool has_denorm_loss = false; - static const bool is_iec559 = false; - static const bool is_bounded = true; - static const bool is_modulo = false; - static const bool traps = false; - static const bool tinyness_before = false; - static const float_denorm_style has_denorm = denorm_indeterminate; - static const float_round_style round_style = round_indeterminate; + static ETL_CONSTANT bool is_specialized = true; + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_integer = false; + static ETL_CONSTANT bool is_exact = false; + static ETL_CONSTANT int radix = 2; + static ETL_CONSTANT bool has_infinity = true; + static ETL_CONSTANT bool has_quiet_NaN = ETL_HAS_NAN; + static ETL_CONSTANT bool has_signaling_NaN = ETL_HAS_NAN; + static ETL_CONSTANT bool has_denorm_loss = false; + static ETL_CONSTANT bool is_iec559 = false; + static ETL_CONSTANT bool is_bounded = true; + static ETL_CONSTANT bool is_modulo = false; + static ETL_CONSTANT bool traps = false; + static ETL_CONSTANT bool tinyness_before = false; + static ETL_CONSTANT float_denorm_style has_denorm = denorm_indeterminate; + static ETL_CONSTANT float_round_style round_style = round_indeterminate; static float round_error() { return float(0.5); } }; @@ -191,10 +191,10 @@ namespace etl { public: - static const int digits = 1; - static const int digits10 = 0; - static const bool is_signed = false; - static const bool is_modulo = false; + static ETL_CONSTANT int digits = 1; + static ETL_CONSTANT int digits10 = 0; + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = false; static bool min() { return false; } static bool max() { return true; } @@ -214,10 +214,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(char)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = etl::is_signed::value; - static const bool is_modulo = false; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + static ETL_CONSTANT bool is_modulo = false; static char min() { return char(CHAR_MIN); } static char max() { return char(CHAR_MAX); } @@ -237,10 +237,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(unsigned char)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = false; - static const bool is_modulo = true; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned char)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; static unsigned char min() { return 0U; } static unsigned char max() { return UCHAR_MAX; } @@ -260,10 +260,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(char)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = true; - static const bool is_modulo = false; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; static signed char min() { return SCHAR_MIN; } static signed char max() { return SCHAR_MAX; } @@ -284,10 +284,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(char16_t)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = false; - static const bool is_modulo = true; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char16_t)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; static char16_t min() { return 0U; } static char16_t max() { return UINT_LEAST16_MAX; } @@ -307,10 +307,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(char32_t)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = false; - static const bool is_modulo = true; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char32_t)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; static char32_t min() { return 0U; } static char32_t max() { return UINT_LEAST32_MAX; } @@ -332,10 +332,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(wchar_t)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = etl::is_signed::value; - static const bool is_modulo = etl::is_unsigned::value; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(wchar_t)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + static ETL_CONSTANT bool is_modulo = etl::is_unsigned::value; static wchar_t min() { return WCHAR_MIN; } static wchar_t max() { return WCHAR_MAX; } @@ -355,10 +355,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(short)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = true; - static const bool is_modulo = false; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(short)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; static short min() { return SHRT_MIN; } static short max() { return SHRT_MAX; } @@ -378,10 +378,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(unsigned short)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = false; - static const bool is_modulo = true; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned short)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; static unsigned short min() { return 0U; } static unsigned short max() { return USHRT_MAX; } @@ -402,10 +402,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(int)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = true; - static const bool is_modulo = false; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(int)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; static int min() { return INT_MIN; } static int max() { return INT_MAX; } @@ -425,10 +425,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(unsigned int)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = false; - static const bool is_modulo = true; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned int)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; static unsigned int min() { return 0U; } static unsigned int max() { return UINT_MAX; } @@ -448,10 +448,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(long)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = true; - static const bool is_modulo = false; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(long)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; static long min() { return LONG_MIN; } static long max() { return LONG_MAX; } @@ -471,10 +471,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(unsigned long)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = false; - static const bool is_modulo = true; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned long)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; static unsigned long min() { return 0U; } static unsigned long max() { return ULONG_MAX; } @@ -494,10 +494,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(long long)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = true; - static const bool is_modulo = false; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(long long)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; static long long min() { return LLONG_MIN; } static long long max() { return LLONG_MAX; } @@ -517,10 +517,10 @@ namespace etl { public: - static const int digits = (CHAR_BIT * sizeof(unsigned long long)) - (etl::is_signed::value ? 1 : 0); - static const int digits10 = ETL_LOG10_OF_2(digits); - static const bool is_signed = false; - static const bool is_modulo = true; + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned long long)) - (etl::is_signed::value ? 1 : 0); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; static unsigned long long min() { return 0U; } static unsigned long long max() { return ULLONG_MAX; } @@ -549,14 +549,14 @@ 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 max_digits10 = ETL_LOG10_OF_2(FLT_MANT_DIG) + 2; + static ETL_CONSTANT int digits = FLT_MANT_DIG; + static ETL_CONSTANT int digits10 = FLT_DIG; + static ETL_CONSTANT int max_digits10 = ETL_LOG10_OF_2(FLT_MANT_DIG) + 2; - 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_exponent10 = FLT_MAX_10_EXP; + static ETL_CONSTANT int min_exponent = FLT_MIN_EXP; + static ETL_CONSTANT int min_exponent10 = FLT_MIN_10_EXP; + static ETL_CONSTANT int max_exponent = FLT_MAX_EXP; + static ETL_CONSTANT int max_exponent10 = FLT_MAX_10_EXP; }; //*************************************************************************** @@ -575,14 +575,14 @@ 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 max_digits10 = ETL_LOG10_OF_2(DBL_MANT_DIG) + 2; + static ETL_CONSTANT int digits = DBL_MANT_DIG; + static ETL_CONSTANT int digits10 = DBL_DIG; + static ETL_CONSTANT int max_digits10 = ETL_LOG10_OF_2(DBL_MANT_DIG) + 2; - 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_exponent10 = DBL_MAX_10_EXP; + static ETL_CONSTANT int min_exponent = DBL_MIN_EXP; + static ETL_CONSTANT int min_exponent10 = DBL_MIN_10_EXP; + static ETL_CONSTANT int max_exponent = DBL_MAX_EXP; + static ETL_CONSTANT int max_exponent10 = DBL_MAX_10_EXP; }; //*************************************************************************** @@ -601,14 +601,14 @@ 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 max_digits10 = ETL_LOG10_OF_2(LDBL_MANT_DIG) + 2; + static ETL_CONSTANT int digits = LDBL_MANT_DIG; + static ETL_CONSTANT int digits10 = LDBL_DIG; + static ETL_CONSTANT int max_digits10 = ETL_LOG10_OF_2(LDBL_MANT_DIG) + 2; - 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_exponent10 = LDBL_MAX_10_EXP; + static ETL_CONSTANT int min_exponent = LDBL_MIN_EXP; + static ETL_CONSTANT int min_exponent10 = LDBL_MIN_10_EXP; + static ETL_CONSTANT int max_exponent = LDBL_MAX_EXP; + static ETL_CONSTANT int max_exponent10 = LDBL_MAX_10_EXP; }; } diff --git a/include/etl/log.h b/include/etl/log.h index f8de2ec8..c06fa661 100644 --- a/include/etl/log.h +++ b/include/etl/log.h @@ -51,7 +51,7 @@ namespace etl ///\tparam NV The number to find the log of. ///\tparam BASE The base of the log. //*************************************************************************** - template + template struct log { enum value_type @@ -64,7 +64,7 @@ namespace etl //*************************************************************************** // Specialisation for N = 1 //*************************************************************************** - template + template struct log<1, BASE> { enum value_type @@ -76,7 +76,7 @@ namespace etl //*************************************************************************** // Specialisation for N = 0 //*************************************************************************** - template + template struct log<0, BASE> { enum value_type @@ -85,6 +85,11 @@ namespace etl }; }; +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t log_v = log::value; +#endif + //*************************************************************************** ///\ingroup log /// Calculates base 2 logs. @@ -98,6 +103,11 @@ namespace etl }; }; +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t log2_v = log2::value; +#endif + //*************************************************************************** ///\ingroup log /// Calculates base 10 logs. @@ -110,6 +120,11 @@ namespace etl value = log::value }; }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t log10_v = log10::value; +#endif } #endif diff --git a/include/etl/negative.h b/include/etl/negative.h index 5c3fe48e..82ba5ee9 100644 --- a/include/etl/negative.h +++ b/include/etl/negative.h @@ -39,7 +39,8 @@ namespace etl // For signed types. //*************************************************************************** template - typename etl::enable_if::value, bool>::type + ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type is_negative(const T value) { return (value < T(0)); @@ -49,6 +50,7 @@ namespace etl // For unsigned types. //*************************************************************************** template + ETL_CONSTEXPR typename etl::enable_if::value, bool>::type is_negative(const T) { diff --git a/include/etl/permutations.h b/include/etl/permutations.h index 8101f8a7..c98e0ad2 100644 --- a/include/etl/permutations.h +++ b/include/etl/permutations.h @@ -46,7 +46,7 @@ namespace etl template struct permutations { - static const size_t value = NV * permutations::value; + static ETL_CONSTANT size_t value = NV * permutations::value; }; //*************************************************************************** @@ -56,8 +56,13 @@ namespace etl template struct permutations { - static const size_t value = 1; + static ETL_CONSTANT size_t value = 1; }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t permutations_v = permutations::value; +#endif } #endif diff --git a/include/etl/platform.h b/include/etl/platform.h index 079eca9b..ac20d4a8 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -170,11 +170,13 @@ SOFTWARE. #define ETL_IF_CONSTEXPR constexpr #define ETL_NODISCARD [[nodiscard]] #define ETL_FALLTHROUGH [[fallthrough]] + #define ETL_INLINE_VAR inline #else #define ETL_CONSTEXPR17 #define ETL_IF_CONSTEXPR #define ETL_NODISCARD #define ETL_FALLTHROUGH + #define ETL_INLINE_VAR #endif // C++20 diff --git a/include/etl/power.h b/include/etl/power.h index 187b061f..22f1c10f 100644 --- a/include/etl/power.h +++ b/include/etl/power.h @@ -60,7 +60,7 @@ namespace etl template struct power { - static const private_power::type value = NV * power::value; + static ETL_CONSTANT private_power::type value = NV * power::value; }; //*************************************************************************** @@ -71,9 +71,14 @@ namespace etl template struct power { - static const private_power::type value = 1; + static ETL_CONSTANT private_power::type value = 1; }; +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t power_v = power::value; +#endif + //*************************************************************************** ///\ingroup power /// Calculates the rounded up power of 2. @@ -101,6 +106,11 @@ namespace etl }; }; +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t power_of_2_round_up_v = power_of_2_round_up::value; +#endif + //*************************************************************************** ///\ingroup power /// Calculates the rounded down power of 2. @@ -156,6 +166,11 @@ namespace etl }; }; +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t power_of_2_round_down_v = power_of_2_round_down::value; +#endif + //*************************************************************************** ///\ingroup power /// Checks if N is a power of 2. @@ -163,7 +178,7 @@ namespace etl template struct is_power_of_2 { - static const bool value = (NV & (NV - 1)) == 0; + static ETL_CONSTANT bool value = (NV & (NV - 1)) == 0; }; //*************************************************************************** @@ -174,7 +189,7 @@ namespace etl template <> struct is_power_of_2<0> { - static const bool value = false; + static ETL_CONSTANT bool value = false; }; //*************************************************************************** @@ -185,8 +200,13 @@ namespace etl template <> struct is_power_of_2<1> { - static const bool value = false; + static ETL_CONSTANT bool value = false; }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t is_power_of_2_v = is_power_of_2::value; +#endif } #endif diff --git a/include/etl/ratio.h b/include/etl/ratio.h index 6bd79c7c..cc80b760 100644 --- a/include/etl/ratio.h +++ b/include/etl/ratio.h @@ -41,8 +41,8 @@ namespace etl template struct ratio { - static const intmax_t num = NUM; - static const intmax_t den = DEN; + static ETL_CONSTANT intmax_t num = NUM; + static ETL_CONSTANT intmax_t den = DEN; }; #if INT_MAX > INT32_MAX diff --git a/include/etl/smallest.h b/include/etl/smallest.h index 92f34a80..540765e7 100644 --- a/include/etl/smallest.h +++ b/include/etl/smallest.h @@ -109,6 +109,17 @@ namespace etl size = etl::size_of::value }; }; + +#if ETL_CPP14_SUPPORTED + template + using smallest_type_t = typename smallest_type::type; +#endif + +#if ETL_CPP17_SUPPORTED + template + constexpr size_t smallest_type_v = smallest_type::size; +#endif + #else //*************************************************************************** /// Template to determine the smallest type and size. @@ -273,7 +284,7 @@ namespace etl /// Defines 'type' which is the type of the smallest unsigned integer. ///\ingroup smallest //*************************************************************************** - template + template struct smallest_uint_for_bits { private: @@ -288,13 +299,18 @@ namespace etl typedef typename private_smallest::best_fit_uint_type::type type; }; +#if ETL_CPP14_SUPPORTED + template + using smallest_uint_for_bits_t = typename smallest_uint_for_bits::type; +#endif + //*************************************************************************** /// Template to determine the smallest signed int type that can contain a /// value with the specified number of bits. /// Defines 'type' which is the type of the smallest signed integer. ///\ingroup smallest //*************************************************************************** - template + template struct smallest_int_for_bits { private: @@ -309,13 +325,18 @@ namespace etl typedef typename private_smallest::best_fit_int_type::type type; }; +#if ETL_CPP14_SUPPORTED + template + using smallest_int_for_bits_t = typename smallest_int_for_bits::type; +#endif + //*************************************************************************** /// Template to determine the smallest unsigned int type that can contain the /// specified unsigned value. /// Defines 'type' which is the type of the smallest unsigned integer. ///\ingroup smallest //*************************************************************************** - template + template struct smallest_uint_for_value { private: @@ -330,6 +351,11 @@ namespace etl typedef typename private_smallest::best_fit_uint_type::type type; }; +#if ETL_CPP14_SUPPORTED + template + using smallest_uint_for_value_t = typename smallest_uint_for_value::type; +#endif + //*************************************************************************** /// Template to determine the smallest int type that can contain the /// specified signed value. @@ -350,6 +376,11 @@ namespace etl typedef typename private_smallest::best_fit_int_type::type type; }; + +#if ETL_CPP14_SUPPORTED + template + using smallest_int_for_value_t = typename smallest_int_for_value::type; +#endif } #endif diff --git a/include/etl/sqrt.h b/include/etl/sqrt.h index 5702c5ae..224a9f9f 100644 --- a/include/etl/sqrt.h +++ b/include/etl/sqrt.h @@ -42,7 +42,7 @@ namespace etl //*************************************************************************** /// Calculates the smallest value that, when squared, will be not greater than VALUE. //*************************************************************************** - template + template struct sqrt { typedef typename etl::conditional<((I * I) > VALUE), @@ -59,6 +59,11 @@ namespace etl }; #endif }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t sqrt_v = sqrt::value; +#endif } #endif diff --git a/include/etl/type_lookup.h b/include/etl/type_lookup.h index c2c46ae6..1042eccd 100644 --- a/include/etl/type_lookup.h +++ b/include/etl/type_lookup.h @@ -117,8 +117,10 @@ namespace etl static_assert(!(etl::is_same::value), "Invalid id"); }; +#if ETL_CPP14_SUPPORTED template using type_from_id_t = typename type_from_id::type; +#endif private: @@ -211,9 +213,11 @@ namespace etl static_assert(!etl::is_same::value, "Type match not found"); }; +#if ETL_CPP14_SUPPORTED // Template alias. template - using TypeFromType_t = typename type_from_type::type; + using type_from_type_t = typename type_from_type::type; +#endif }; #else diff --git a/include/etl/type_select.h b/include/etl/type_select.h index 9d34f388..44e15561 100644 --- a/include/etl/type_select.h +++ b/include/etl/type_select.h @@ -82,8 +82,10 @@ namespace etl using type = typename type_select_helper::type; }; +#if ETL_CPP14_SUPPORTED template using select_t = typename select::type; +#endif }; #else diff --git a/test/test_alignment.cpp b/test/test_alignment.cpp index aae3faf1..4928554a 100644 --- a/test/test_alignment.cpp +++ b/test/test_alignment.cpp @@ -41,7 +41,7 @@ SOFTWARE. #endif #ifdef ETL_COMPILER_GCC - #pragma GCC diagnostic ignored "-Wno-deprecated" + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif void f(int) diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index 1a7ebb4e..73a6c043 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -172,6 +172,20 @@ namespace CHECK_THROW(d(), etl::delegate_uninitialised); } + SUITE(test_constexpr_delegate) + { + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_is_valid_false) + { + constexpr etl::delegate d; + + CHECK(!d.is_valid()); + CHECK(!d); + + CHECK_THROW(d(), etl::delegate_uninitialised); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_is_valid_true) { @@ -192,6 +206,16 @@ namespace CHECK(function_called); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_free_void_constexpr) + { + constexpr auto d = etl::delegate::create(); + + d(); + + CHECK(function_called); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_int) { @@ -203,6 +227,17 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_free_int_constexpr) + { + constexpr auto d = etl::delegate::create(); + + d(VALUE1, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_reference) { @@ -217,6 +252,20 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_free_reference_constexpr) + { + constexpr etl::delegate d = etl::delegate::create(); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_lambda_int) { @@ -265,6 +314,18 @@ namespace CHECK(function_called); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_operator_void_create_constexpr) + { + static Test test; + + constexpr auto d = etl::delegate::create(test); + + d(); + + CHECK(function_called); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void_const) { @@ -288,6 +349,16 @@ namespace CHECK(function_called); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_constexpr) + { + constexpr auto d = etl::delegate::create(); + + d(); + + CHECK(function_called); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_const) { @@ -297,6 +368,16 @@ namespace CHECK(function_called); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_const_constexpr) + { + constexpr auto d = etl::delegate::create(); + + d(); + + CHECK(function_called); + } #endif //************************************************************************* @@ -325,6 +406,18 @@ namespace CHECK(function_called); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_void_constexpr) + { + static Test test; + + constexpr auto d = etl::delegate::create(test); + + d(); + + CHECK(function_called); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_const) { @@ -337,6 +430,18 @@ namespace CHECK(function_called); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_void_const_constexpr) + { + static const Test test; + + constexpr auto d = etl::delegate::create(test); + + d(); + + CHECK(function_called); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int) { @@ -350,6 +455,19 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_int_constexpr) + { + static Test test; + + constexpr auto d = etl::delegate::create(test); + + d(VALUE1, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_const) { @@ -363,6 +481,19 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_int_const_constexpr) + { + static const Test test; + + constexpr auto d = etl::delegate::create(test); + + d(VALUE1, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_reference) { @@ -378,6 +509,21 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_reference_constexpr) + { + static Test test; + constexpr auto d = etl::delegate::create(test); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_reference_const) { @@ -393,6 +539,21 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_reference_const_constexpr) + { + static const Test test; + constexpr auto d = etl::delegate::create(test); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_static) { @@ -407,6 +568,20 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_static_constexpr) + { + constexpr auto d = etl::delegate::create(); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + #if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 5)) //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_compile_time) @@ -418,6 +593,16 @@ namespace CHECK(function_called); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_void_compile_time_constexpr) + { + constexpr auto d = etl::delegate::create(); + + d(); + + CHECK(function_called); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_const_compile_time) { @@ -428,6 +613,16 @@ namespace CHECK(function_called); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_void_const_compile_time_constexpr) + { + constexpr auto d = etl::delegate::create(); + + d(); + + CHECK(function_called); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_compile_time) { @@ -439,6 +634,17 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_int_compile_time_constexpr) + { + constexpr auto d = etl::delegate::create(); + + d(VALUE1, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_const_compile_time) { @@ -450,6 +656,17 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_int_const_compile_time_constexpr) + { + constexpr auto d = etl::delegate::create(); + + d(VALUE1, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_reference_compile_time) { @@ -464,6 +681,20 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_reference_compile_time_constexpr) + { + constexpr auto d = etl::delegate::create(); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_reference_const_compile_time) { @@ -477,6 +708,20 @@ namespace CHECK(function_called); CHECK(parameter_correct); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_member_reference_const_compile_time_constexpr) + { + constexpr auto d = etl::delegate::create(); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } #endif //************************************************************************* @@ -493,6 +738,20 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_construct_constexpr) + { + static Test test; + + constexpr auto d1 = etl::delegate::create(test); + constexpr auto d2(d1); + + d2(VALUE1, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assignment) { diff --git a/test/test_largest.cpp b/test/test_largest.cpp index 20c090f5..8c9ca6bd 100644 --- a/test/test_largest.cpp +++ b/test/test_largest.cpp @@ -55,6 +55,25 @@ namespace CHECK(type); } + //************************************************************************* + TEST(test_pod_type_vt) + { + size_t size; + bool type; + + size = etl::largest_type_v; + type = etl::is_same>::value; + + CHECK_EQUAL(sizeof(int), size); + CHECK(type); + + size = etl::largest_type_v; + type = etl::is_same>::value; + + CHECK_EQUAL(sizeof(int), size); + CHECK(type); + } + //************************************************************************* TEST(test_non_pod_type) { @@ -78,6 +97,29 @@ namespace CHECK(type); } + //************************************************************************* + TEST(test_non_pod_type_vt) + { + size_t size; + bool type; + + struct S1 { char a; char b; char c; }; + struct S2 { char a; short b; char c; }; + struct S3 { int a; short b; char c; }; + + size = etl::largest_type_v; + type = etl::is_same>::value; + + CHECK_EQUAL(sizeof(S3), size); + CHECK(type); + + size = etl::largest_type_v; + type = etl::is_same>::value; + + CHECK_EQUAL(sizeof(S3), size); + CHECK(type); + } + //************************************************************************* TEST(test_pod_alignment) { @@ -86,6 +128,14 @@ namespace CHECK_EQUAL(std::alignment_of::value, size); } + //************************************************************************* + TEST(test_pod_alignment_v) + { + size_t size = etl::largest_alignment_v; + + CHECK_EQUAL(std::alignment_of::value, size); + } + //************************************************************************* TEST(test_non_pod_alignment) { @@ -98,6 +148,18 @@ namespace CHECK_EQUAL(std::alignment_of::value, size); } + //************************************************************************* + TEST(test_non_pod_alignment_v) + { + struct S1 { char a; char b; char c; }; + struct S2 { char a; short b; char c; }; + struct S3 { int a; short b; char c; }; + + size_t size = etl::largest_alignment_v; + + CHECK_EQUAL(std::alignment_of::value, size); + } + //************************************************************************* TEST(test_larger_int_type) { @@ -112,6 +174,20 @@ namespace CHECK(bool(etl::is_same::type, int64_t>::value)); } + //************************************************************************* + TEST(test_larger_int_type_t) + { + CHECK(bool(etl::is_same, int16_t>::value)); + CHECK(bool(etl::is_same, int32_t>::value)); + CHECK(bool(etl::is_same, int64_t>::value)); + CHECK(bool(etl::is_same, int64_t>::value)); + + CHECK(bool(etl::is_same, int16_t>::value)); + CHECK(bool(etl::is_same, int32_t>::value)); + CHECK(bool(etl::is_same, int64_t>::value)); + CHECK(bool(etl::is_same, int64_t>::value)); + } + //************************************************************************* TEST(test_larger_uint_type) { @@ -126,6 +202,20 @@ namespace CHECK(bool(etl::is_same::type, uint64_t>::value)); } + //************************************************************************* + TEST(test_larger_uint_type_t) + { + CHECK(bool(etl::is_same, uint16_t>::value)); + CHECK(bool(etl::is_same, uint32_t>::value)); + CHECK(bool(etl::is_same, uint64_t>::value)); + CHECK(bool(etl::is_same, uint64_t>::value)); + + CHECK(bool(etl::is_same, uint16_t>::value)); + CHECK(bool(etl::is_same, uint32_t>::value)); + CHECK(bool(etl::is_same, uint64_t>::value)); + CHECK(bool(etl::is_same, uint64_t>::value)); + } + //************************************************************************* TEST(test_larger_type) { @@ -139,5 +229,19 @@ namespace CHECK(bool(etl::is_same::type, uint64_t>::value)); CHECK(bool(etl::is_same::type, uint64_t>::value)); } + + //************************************************************************* + TEST(test_larger_type_t) + { + CHECK(bool(etl::is_same, int16_t>::value)); + CHECK(bool(etl::is_same, int32_t>::value)); + CHECK(bool(etl::is_same, int64_t>::value)); + CHECK(bool(etl::is_same, int64_t>::value)); + + CHECK(bool(etl::is_same, uint16_t>::value)); + CHECK(bool(etl::is_same, uint32_t>::value)); + CHECK(bool(etl::is_same, uint64_t>::value)); + CHECK(bool(etl::is_same, uint64_t>::value)); + } }; } diff --git a/test/test_smallest.cpp b/test/test_smallest.cpp index d63911c0..2e8591da 100644 --- a/test/test_smallest.cpp +++ b/test/test_smallest.cpp @@ -55,6 +55,25 @@ namespace CHECK(type); } + //************************************************************************* + TEST(test_pod_vt) + { + size_t size; + bool type; + + size = etl::smallest_type_v; + type = etl::is_same>::value; + + CHECK_EQUAL(sizeof(char), size); + CHECK(type); + + size = etl::smallest_type::size; + type = etl::is_same::type>::value; + + CHECK_EQUAL(sizeof(char), size); + CHECK(type); + } + //************************************************************************* TEST(test_non_pod) { @@ -78,6 +97,29 @@ namespace CHECK(type); } + //************************************************************************* + TEST(test_non_pod_vt) + { + size_t size; + bool type; + + struct S1 { char a; char b; char c; }; + struct S2 { char a; short b; char c; }; + struct S3 { int a; short b; char c; }; + + size = etl::smallest_type_v; + type = etl::is_same>::value; + + CHECK_EQUAL(sizeof(S1), size); + CHECK(type); + + size = etl::smallest_type_v; + type = etl::is_same>::value; + + CHECK_EQUAL(sizeof(S1), size); + CHECK(type); + } + //************************************************************************* TEST(test_smallest_uint_for_bits) { @@ -120,6 +162,48 @@ namespace CHECK(type); } + //************************************************************************* + TEST(test_smallest_uint_for_bits_t) + { + bool type; + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + } + //************************************************************************* TEST(test_smallest_int_for_bits) { @@ -162,6 +246,48 @@ namespace CHECK(type); } + //************************************************************************* + TEST(test_smallest_int_for_bits_t) + { + bool type; + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + } + //************************************************************************* TEST(test_smallest_uint_for_value) { @@ -192,6 +318,36 @@ namespace CHECK(type); } + //************************************************************************* + TEST(test_smallest_uint_for_value_t) + { + bool type; + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + } + //************************************************************************* TEST(test_smallest_int_for_value) { @@ -242,5 +398,56 @@ namespace type = etl::is_same::type>::value; CHECK(type); } + + //************************************************************************* + TEST(test_smallest_int_for_value_t) + { + bool type; + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + + type = etl::is_same>::value; + CHECK(type); + } }; } diff --git a/test/test_type_lookup.cpp b/test/test_type_lookup.cpp index 2ecb4c65..8c2118fb 100644 --- a/test/test_type_lookup.cpp +++ b/test/test_type_lookup.cpp @@ -135,6 +135,27 @@ namespace CHECK((etl::is_same::type>::value)); } + //************************************************************************* + TEST(test_type_from_id_t_16) + { + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + } + //************************************************************************* TEST(test_type_from_id_8) { @@ -148,12 +169,31 @@ namespace CHECK((etl::is_same::type>::value)); } + //************************************************************************* + TEST(test_type_from_id_t_8) + { + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + } + //************************************************************************* TEST(test_type_from_id_1) { CHECK((etl::is_same::type>::value)); } + //************************************************************************* + TEST(test_type_from_id_t_1) + { + CHECK((etl::is_same>::value)); + } + //************************************************************************* TEST(test_id_from_type_16) { @@ -208,6 +248,27 @@ namespace CHECK_EQUAL((unsigned int)Type16::ID, (unsigned int)Type_Id_Lookup16::get_id_from_type(Type16())); } + //************************************************************************* + TEST(test_id_from_type_v_16) + { + CHECK_EQUAL((unsigned int)Type1::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type2::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type3::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type4::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type5::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type6::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type7::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type8::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type9::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type10::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type11::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type12::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type13::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type14::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type15::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + CHECK_EQUAL((unsigned int)Type16::ID, (unsigned int)Type_Id_Lookup16::id_from_type_v); + } + //************************************************************************* TEST(test_id_from_type_8) { @@ -236,7 +297,19 @@ namespace CHECK_EQUAL((unsigned int)Type15::ID, (unsigned int)Type_Id_Lookup8::get_id_from_type(Type15())); CHECK_EQUAL((unsigned int)Type16::ID, (unsigned int)Type_Id_Lookup8::get_id_from_type()); CHECK_EQUAL((unsigned int)Type16::ID, (unsigned int)Type_Id_Lookup8::get_id_from_type(Type16())); + } + //************************************************************************* + TEST(test_id_from_type_v_8) + { + CHECK_EQUAL((unsigned int)Type1::ID, (unsigned int)Type_Id_Lookup8::id_from_type_v); + CHECK_EQUAL((unsigned int)Type2::ID, (unsigned int)Type_Id_Lookup8::id_from_type_v); + CHECK_EQUAL((unsigned int)Type3::ID, (unsigned int)Type_Id_Lookup8::id_from_type_v); + CHECK_EQUAL((unsigned int)Type4::ID, (unsigned int)Type_Id_Lookup8::id_from_type_v); + CHECK_EQUAL((unsigned int)Type13::ID, (unsigned int)Type_Id_Lookup8::id_from_type_v); + CHECK_EQUAL((unsigned int)Type14::ID, (unsigned int)Type_Id_Lookup8::id_from_type_v); + CHECK_EQUAL((unsigned int)Type15::ID, (unsigned int)Type_Id_Lookup8::id_from_type_v); + CHECK_EQUAL((unsigned int)Type16::ID, (unsigned int)Type_Id_Lookup8::id_from_type_v); } //************************************************************************* @@ -248,6 +321,12 @@ namespace CHECK_EQUAL((unsigned int)Type16::ID, (unsigned int)Type_Id_Lookup1::get_id_from_type(Type16())); } + //************************************************************************* + TEST(test_id_from_type_v_1) + { + CHECK_EQUAL((unsigned int)Type16::ID, (unsigned int)Type_Id_Lookup1::id_from_type_v); + } + //************************************************************************* TEST(test_type_from_type_16) { @@ -269,6 +348,27 @@ namespace CHECK((etl::is_same::type>::value)); } + //************************************************************************* + TEST(test_type_from_type_t_16) + { + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + } + //************************************************************************* TEST(test_type_from_type_8) { @@ -282,10 +382,29 @@ namespace CHECK((etl::is_same::type>::value)); } + //************************************************************************* + TEST(test_type_from_type_t_8) + { + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + CHECK((etl::is_same>::value)); + } + //************************************************************************* TEST(test_type_from_type_1) { CHECK((etl::is_same::type>::value)); } + + //************************************************************************* + TEST(test_type_from_type_t_1) + { + CHECK((etl::is_same>::value)); + } }; } diff --git a/test/test_type_select.cpp b/test/test_type_select.cpp index 2d35e701..7e37aeee 100644 --- a/test/test_type_select.cpp +++ b/test/test_type_select.cpp @@ -49,14 +49,21 @@ namespace SUITE(test_type_lookup) { //************************************************************************* - TEST(test_type_select1) + TEST(test_type_select_1) { CHECK((etl::is_same, typename Types1::select<0>::type>::value)); CHECK(!(etl::is_same, typename Types1::select<0>::type>::value)); } //************************************************************************* - TEST(test_type_select8) + TEST(test_type_select_t_1) + { + CHECK((etl::is_same, typename Types1::select_t<0>>::value)); + CHECK(!(etl::is_same, typename Types1::select_t<0>>::value)); + } + + //************************************************************************* + TEST(test_type_select_8) { CHECK((etl::is_same, typename Types8::select<0>::type>::value)); CHECK(!(etl::is_same, typename Types8::select<0>::type>::value)); @@ -77,7 +84,28 @@ namespace } //************************************************************************* - TEST(test_type_select16) + TEST(test_type_select_t_8) + { + CHECK((etl::is_same, typename Types8::select_t<0>>::value)); + CHECK(!(etl::is_same, typename Types8::select_t<0>>::value)); + CHECK((etl::is_same, typename Types8::select_t<1>>::value)); + CHECK(!(etl::is_same, typename Types8::select_t<1>>::value)); + CHECK((etl::is_same, typename Types8::select_t<2>>::value)); + CHECK(!(etl::is_same, typename Types8::select_t<2>>::value)); + CHECK((etl::is_same, typename Types8::select_t<3>>::value)); + CHECK(!(etl::is_same, typename Types8::select_t<3>>::value)); + CHECK((etl::is_same, typename Types8::select_t<4>>::value)); + CHECK(!(etl::is_same, typename Types8::select_t<4>>::value)); + CHECK((etl::is_same, typename Types8::select_t<5>>::value)); + CHECK(!(etl::is_same, typename Types8::select_t<5>>::value)); + CHECK((etl::is_same, typename Types8::select_t<6>>::value)); + CHECK(!(etl::is_same, typename Types8::select_t<6>>::value)); + CHECK((etl::is_same, typename Types8::select_t<7>>::value)); + CHECK(!(etl::is_same, typename Types8::select_t<7>>::value)); + } + + //************************************************************************* + TEST(test_type_select_16) { CHECK((etl::is_same, typename Types16::select<0>::type>::value)); CHECK(!(etl::is_same, typename Types16::select<0>::type>::value)); @@ -112,5 +140,42 @@ namespace CHECK((etl::is_same, typename Types16::select<15>::type>::value)); CHECK(!(etl::is_same, typename Types16::select<15>::type>::value)); } + + //************************************************************************* + TEST(test_type_select_t_16) + { + CHECK((etl::is_same, typename Types16::select_t<0>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<0>>::value)); + CHECK((etl::is_same, typename Types16::select_t<1>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<1>>::value)); + CHECK((etl::is_same, typename Types16::select_t<2>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<2>>::value)); + CHECK((etl::is_same, typename Types16::select_t<3>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<3>>::value)); + CHECK((etl::is_same, typename Types16::select_t<4>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<4>>::value)); + CHECK((etl::is_same, typename Types16::select_t<5>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<5>>::value)); + CHECK((etl::is_same, typename Types16::select_t<6>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<6>>::value)); + CHECK((etl::is_same, typename Types16::select_t<7>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<7>>::value)); + CHECK((etl::is_same, typename Types16::select_t<8>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<8>>::value)); + CHECK((etl::is_same, typename Types16::select_t<9>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<9>>::value)); + CHECK((etl::is_same, typename Types16::select_t<10>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<10>>::value)); + CHECK((etl::is_same, typename Types16::select_t<11>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<11>>::value)); + CHECK((etl::is_same, typename Types16::select_t<12>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<12>>::value)); + CHECK((etl::is_same, typename Types16::select_t<13>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<13>>::value)); + CHECK((etl::is_same, typename Types16::select_t<14>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<14>>::value)); + CHECK((etl::is_same, typename Types16::select_t<15>>::value)); + CHECK(!(etl::is_same, typename Types16::select_t<15>>::value)); + } }; }