From aa1d7f0f7f2c4511cbe0f89efdab15b699d77d77 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Apr 2023 09:28:37 +0100 Subject: [PATCH] Conversion of static to C++14 compatinility --- .gitignore | 4 + include/etl/basic_string.h | 23 +- include/etl/fsm.h | 16 +- include/etl/functional.h | 5 + include/etl/generators/fsm_generator.h | 11 +- .../etl/generators/message_packet_generator.h | 4 +- .../etl/generators/type_lookup_generator.h | 4 +- .../etl/generators/type_traits_generator.h | 56 +- include/etl/integral_limits.h | 598 +++++++--- include/etl/limits.h | 1008 +++++++++++------ include/etl/parameter_pack.h | 10 + include/etl/private/bitset_legacy.h | 9 + include/etl/private/bitset_new.h | 66 +- include/etl/private/variant_variadic.h | 6 +- include/etl/smallest.h | 8 +- include/etl/span.h | 3 + include/etl/sqrt.h | 5 + include/etl/type_traits.h | 91 +- include/etl/unaligned_type.h | 9 + test/UnitTest++/Checks.h | 12 +- test/etl_initializer_list/CMakeLists.txt | 23 +- test/runtests-O1.sh | 238 ---- test/runtests-O2.sh | 238 ---- test/runtests-O3.sh | 238 ---- test/runtests-c++14.sh | 348 ------ test/runtests.sh | 464 ++++---- test/test_numeric.cpp | 1 + test/test_to_arithmetic.cpp | 1 + test/test_to_arithmetic_u16.cpp | 1 + test/test_to_arithmetic_u32.cpp | 1 + test/test_to_arithmetic_wchar_t.cpp | 1 + test/vs2022/cpp.hint | 19 +- test/vs2022/etl.vcxproj | 4 - test/vs2022/etl.vcxproj.filters | 14 +- 34 files changed, 1532 insertions(+), 2007 deletions(-) delete mode 100644 test/runtests-O1.sh delete mode 100644 test/runtests-O2.sh delete mode 100644 test/runtests-O3.sh delete mode 100644 test/runtests-c++14.sh diff --git a/.gitignore b/.gitignore index 5c8a2e4c..4f2b0c76 100644 --- a/.gitignore +++ b/.gitignore @@ -379,3 +379,7 @@ test/vs2022/Debug MSVC - No STL - Force Built-ins test/temp test/vs2022/Debug MSVC C++14 test/vs2022/Debug MSVC C++20 - No STL +build-test-Desktop_x86_windows_msvc2019_pe_64bit-Debug +test/vs2022/Debug MSVC C++14 - No STL +test/log.txt +test/etl_error_handler/log.txt diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index f26e7ee7..7d305853 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -144,8 +144,19 @@ namespace etl { public: + typedef size_t size_type; + static ETL_CONSTANT uint_least8_t IS_TRUNCATED = etl::bit<0>::value; static ETL_CONSTANT uint_least8_t CLEAR_AFTER_USE = etl::bit<1>::value; + +#if ETL_USING_CPP11 + static constexpr size_type npos = etl::integral_limits::max; +#else + enum + { + npos = etl::integral_limits::max + }; +#endif }; template @@ -153,6 +164,9 @@ namespace etl template ETL_CONSTANT uint_least8_t string_base_statics::CLEAR_AFTER_USE; + + template + ETL_CONSTANT typename string_base_statics::size_type string_base_statics::npos; } //*************************************************************************** @@ -162,15 +176,6 @@ namespace etl typedef size_t size_type; -#if ETL_USING_CPP11 - static constexpr size_type npos = etl::integral_limits::max; -#else - enum - { - npos = etl::integral_limits::max - }; -#endif - //************************************************************************* /// Gets the current size of the string. ///\return The current size of the string. diff --git a/include/etl/fsm.h b/include/etl/fsm.h index b8b48fee..0f2eb368 100644 --- a/include/etl/fsm.h +++ b/include/etl/fsm.h @@ -174,27 +174,29 @@ namespace etl template class ifsm_state_helper { + public: + // Pass this whenever no state change is desired. // The highest unsigned value of fsm_state_id_t. static ETL_CONSTANT fsm_state_id_t No_State_Change = etl::integral_limits::max; // Pass this when this event also needs to be passed to the parent. static ETL_CONSTANT fsm_state_id_t Pass_To_Parent = No_State_Change - 1U; }; + + template + ETL_CONSTANT fsm_state_id_t ifsm_state_helper::No_State_Change; + + template + ETL_CONSTANT fsm_state_id_t ifsm_state_helper::Pass_To_Parent; } //*************************************************************************** /// Interface class for FSM states. //*************************************************************************** - class ifsm_state : private_fsm::ifsm_state_helper<> + class ifsm_state : public private_fsm::ifsm_state_helper<> { public: - // Pass this whenever no state change is desired. - // The highest unsigned value of fsm_state_id_t. - static ETL_CONSTANT fsm_state_id_t No_State_Change = etl::integral_limits::max; - // Pass this when this event also needs to be passed to the parent. - static ETL_CONSTANT fsm_state_id_t Pass_To_Parent = No_State_Change - 1U; - /// Allows ifsm_state functions to be private. friend class etl::fsm; friend class etl::hfsm; diff --git a/include/etl/functional.h b/include/etl/functional.h index 0a4bde46..e6a72ad8 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -57,6 +57,11 @@ namespace etl { } + ETL_CONSTEXPR20 reference_wrapper(const reference_wrapper& rhs) ETL_NOEXCEPT + : t(rhs.t) + { + } + ETL_CONSTEXPR20 reference_wrapper& operator = (const reference_wrapper& rhs) ETL_NOEXCEPT { t = rhs.t; diff --git a/include/etl/generators/fsm_generator.h b/include/etl/generators/fsm_generator.h index b5bd4206..6d5e945a 100644 --- a/include/etl/generators/fsm_generator.h +++ b/include/etl/generators/fsm_generator.h @@ -193,18 +193,27 @@ namespace etl template class ifsm_state_helper { + public: + // Pass this whenever no state change is desired. // The highest unsigned value of fsm_state_id_t. static ETL_CONSTANT fsm_state_id_t No_State_Change = etl::integral_limits::max; + // Pass this when this event also needs to be passed to the parent. static ETL_CONSTANT fsm_state_id_t Pass_To_Parent = No_State_Change - 1U; }; + + template + ETL_CONSTANT fsm_state_id_t ifsm_state_helper::No_State_Change; + + template + ETL_CONSTANT fsm_state_id_t ifsm_state_helper::Pass_To_Parent; } //*************************************************************************** /// Interface class for FSM states. //*************************************************************************** - class ifsm_state : private_fsm::ifsm_state_helper<> + class ifsm_state : public private_fsm::ifsm_state_helper<> { public: diff --git a/include/etl/generators/message_packet_generator.h b/include/etl/generators/message_packet_generator.h index 6ada9acd..8a9bf0e0 100644 --- a/include/etl/generators/message_packet_generator.h +++ b/include/etl/generators/message_packet_generator.h @@ -483,7 +483,7 @@ namespace etl for n in range(1, int(Handlers)): cog.out("T%s, " % n) cog.outl("T%s>::value, int>::type>" % int(Handlers)) - cog.outl(" explicit message_packet(TMessage&& msg)") + cog.outl(" explicit message_packet(TMessage&& /*msg*/)") cog.outl(" : valid(true)") cog.outl(" {") generate_static_assert_cpp11(int(Handlers)) @@ -767,7 +767,7 @@ namespace etl for t in range(1, n): cog.out("T%s, " % t) cog.outl("T%s>::value, int>::type>" % n) - cog.outl(" explicit message_packet(TMessage&& msg)") + cog.outl(" explicit message_packet(TMessage&& /*msg*/)") cog.outl(" : valid(true)") cog.outl(" {") generate_static_assert_cpp11(n) diff --git a/include/etl/generators/type_lookup_generator.h b/include/etl/generators/type_lookup_generator.h index 2563729a..bcc10e2d 100644 --- a/include/etl/generators/type_lookup_generator.h +++ b/include/etl/generators/type_lookup_generator.h @@ -137,14 +137,14 @@ namespace etl template struct id_from_type_helper { - static constexpr size_t value = etl::is_same::value ? T1::ID : id_from_type_helper::value; + static constexpr size_t value = etl::is_same::value ? size_t(T1::ID) : id_from_type_helper::value; }; // Specialisation for 1 type pair. template struct id_from_type_helper { - static constexpr size_t value = etl::is_same::value ? T1::ID : UNKNOWN; + static constexpr size_t value = etl::is_same::value ? size_t(T1::ID) : UNKNOWN; }; public: diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 83939a93..1518d94d 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -1622,99 +1622,71 @@ namespace etl //********************************************* // is_assignable template - struct is_assignable : public std::is_assignable - { - }; + using is_assignable = std::is_assignable; //********************************************* // is_constructible template - struct is_constructible : public std::is_constructible - { - }; + using is_constructible = std::is_constructible; //********************************************* // is_copy_constructible template - struct is_copy_constructible : public std::is_copy_constructible - { - }; + using is_copy_constructible = std::is_copy_constructible; //********************************************* // is_move_constructible template - struct is_move_constructible : public std::is_move_constructible - { - }; + using is_move_constructible = std::is_move_constructible; //********************************************* // is_trivially_constructible #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template - struct is_trivially_constructible : public std::is_trivially_constructible - { - }; + using is_trivially_constructible = std::is_trivially_constructible; #else template - struct is_trivially_constructible : public etl::bool_constant::value || etl::is_pointer::value> - { - }; + using is_trivially_constructible = etl::bool_constant::value || etl::is_pointer::value>; #endif //********************************************* // is_trivially_copy_constructible #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template - struct is_trivially_copy_constructible : public std::is_trivially_copy_constructible - { - }; + using is_trivially_copy_constructible = std::is_trivially_copy_constructible; #else template - struct is_trivially_copy_constructible : public etl::bool_constant::value || etl::is_pointer::value> - { - }; + using is_trivially_copy_constructible = etl::bool_constant::value || etl::is_pointer::value>; #endif //********************************************* // is_trivially_destructible #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template - struct is_trivially_destructible : public std::is_trivially_destructible - { - }; + using is_trivially_destructible = std::is_trivially_destructible; #else template - struct is_trivially_destructible : public etl::bool_constant::value || etl::is_pointer::value> - { - }; + using is_trivially_destructible = etl::bool_constant::value || etl::is_pointer::value>; #endif //********************************************* // is_trivially_copy_assignable #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template - struct is_trivially_copy_assignable : public std::is_trivially_copy_assignable - { - }; + using is_trivially_copy_assignable = std::is_trivially_copy_assignable; #else template - struct is_trivially_copy_assignable : public etl::bool_constant::value || etl::is_pointer::value> - { - }; + using is_trivially_copy_assignable = etl::bool_constant::value || etl::is_pointer::value>; #endif //********************************************* // is_trivially_copyable #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template - struct is_trivially_copyable : public std::is_trivially_copyable - { - }; + using is_trivially_copyable = std::is_trivially_copyable; #else template - struct is_trivially_copyable : public etl::bool_constant::value || etl::is_pointer::value> - { - }; + using is_trivially_copyable = etl::bool_constant::value || etl::is_pointer::value>; #endif #elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) diff --git a/include/etl/integral_limits.h b/include/etl/integral_limits.h index 07949efb..f7b7c68c 100644 --- a/include/etl/integral_limits.h +++ b/include/etl/integral_limits.h @@ -45,8 +45,422 @@ SOFTWARE. ///\ingroup utilities //***************************************************************************** +#ifndef LLONG_MAX + #define LLONG_MAX 9223372036854775807LL +#endif + +#ifndef LLONG_MIN + #define LLONG_MIN (-LLONG_MAX - 1LL) +#endif + +#ifndef ULLONG_MAX + #define ULLONG_MAX 18446744073709551615ULL +#endif + namespace etl { + namespace private_integral_limits + { + //***************************************************************************** + /// The technique of using templated base classes to declare and define the statics + /// is to get around the limits of the One Definition Rule (ODR) that occurs when + /// the top level integral_limits classes are specialised. This issue currently seems + /// to only be apparent for GCC/C++14. + /// In C++17 and above this is not necessary, as the inline keyword may be used. + /// At the time of writing, the ETL is generally aimed to be compatible with C++98 and above. + //***************************************************************************** + + //********************************* + // signed char + template + struct statics_signed_char + { + typedef signed char value_type; + + static ETL_CONSTANT signed char min = SCHAR_MIN; + static ETL_CONSTANT signed char max = SCHAR_MAX; + static ETL_CONSTANT int bits = CHAR_BIT; + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT signed char statics_signed_char::min; + + template + ETL_CONSTANT signed char statics_signed_char::max; + + template + ETL_CONSTANT int statics_signed_char::bits; + + template + ETL_CONSTANT bool statics_signed_char::is_signed; + + //*********************************** + // unsigned char + template + struct statics_unsigned_char + { + typedef unsigned char value_type; + + static ETL_CONSTANT unsigned char min = 0; + static ETL_CONSTANT unsigned char max = UCHAR_MAX; + static ETL_CONSTANT int bits = CHAR_BIT; + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT unsigned char statics_unsigned_char::min; + + template + ETL_CONSTANT unsigned char statics_unsigned_char::max; + + template + ETL_CONSTANT int statics_unsigned_char::bits; + + template + ETL_CONSTANT bool statics_unsigned_char::is_signed; + + //*********************************** + // char + template + struct statics_char + { + typedef char value_type; + + static ETL_CONSTANT char min = (etl::is_signed::value) ? SCHAR_MIN : 0; + static ETL_CONSTANT char max = (etl::is_signed::value) ? SCHAR_MAX : static_cast(UCHAR_MAX); + static ETL_CONSTANT int bits = CHAR_BIT; + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT char statics_char::min; + + template + ETL_CONSTANT char statics_char::max; + + template + ETL_CONSTANT int statics_char::bits; + + template + ETL_CONSTANT bool statics_char::is_signed; + + //*********************************** + // wchar_t + template + struct statics_wchar_t + { + typedef wchar_t value_type; + + static ETL_CONSTANT wchar_t min = WCHAR_MIN; + static ETL_CONSTANT wchar_t max = WCHAR_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * sizeof(wchar_t); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT wchar_t statics_wchar_t::min; + + template + ETL_CONSTANT wchar_t statics_wchar_t::max; + + template + ETL_CONSTANT int statics_wchar_t::bits; + + template + ETL_CONSTANT bool statics_wchar_t::is_signed; + + //*********************************** + // short +#if defined(ETL_COMPILER_MICROSOFT) + #pragma warning(push) + #pragma warning(disable : 4309) +#endif + + template + struct statics_short + { + typedef short value_type; + + static ETL_CONSTANT short min = SHRT_MIN; + static ETL_CONSTANT short max = SHRT_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(short) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT short statics_short::min; + + template + ETL_CONSTANT short statics_short::max; + + template + ETL_CONSTANT int statics_short::bits; + + template + ETL_CONSTANT bool statics_short::is_signed; + +#if defined(ETL_COMPILER_MICROSOFT) + #pragma warning(pop) +#endif + + //*********************************** + // unsigned short + template + struct statics_unsigned_short + { + typedef unsigned short value_type; + + static ETL_CONSTANT unsigned short min = 0; + static ETL_CONSTANT unsigned short max = USHRT_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned short) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT unsigned short statics_unsigned_short::min; + + template + ETL_CONSTANT unsigned short statics_unsigned_short::max; + + template + ETL_CONSTANT int statics_unsigned_short::bits; + + template + ETL_CONSTANT bool statics_unsigned_short::is_signed; + + //*********************************** + // int + template + struct statics_int + { + typedef int value_type; + + static ETL_CONSTANT int min = INT_MIN; + static ETL_CONSTANT int max = INT_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(int) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT int statics_int::min; + + template + ETL_CONSTANT int statics_int::max; + + template + ETL_CONSTANT int statics_int::bits; + + template + ETL_CONSTANT bool statics_int::is_signed; + + //*********************************** + // unsigned int + template + struct statics_unsigned_int + { + typedef unsigned int value_type; + + static ETL_CONSTANT unsigned int min = 0; + static ETL_CONSTANT unsigned int max = UINT_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned int) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT unsigned int statics_unsigned_int::min; + + template + ETL_CONSTANT unsigned int statics_unsigned_int::max; + + template + ETL_CONSTANT int statics_unsigned_int::bits; + + template + ETL_CONSTANT bool statics_unsigned_int::is_signed; + + //*********************************** + // long + template + struct statics_long + { + typedef long value_type; + + static ETL_CONSTANT long min = LONG_MIN; + static ETL_CONSTANT long max = LONG_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT long statics_long::min; + + template + ETL_CONSTANT long statics_long::max; + + template + ETL_CONSTANT int statics_long::bits; + + template + ETL_CONSTANT bool statics_long::is_signed; + + //*********************************** + // unsigned long + template + struct statics_unsigned_long + { + typedef unsigned long value_type; + + static ETL_CONSTANT unsigned long min = 0; + static ETL_CONSTANT unsigned long max = ULONG_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT unsigned long statics_unsigned_long::min; + + template + ETL_CONSTANT unsigned long statics_unsigned_long::max; + + template + ETL_CONSTANT int statics_unsigned_long::bits; + + template + ETL_CONSTANT bool statics_unsigned_long::is_signed; + + //*********************************** + // long long + template + struct statics_long_long + { + typedef long long value_type; + + static ETL_CONSTANT long long min = LLONG_MIN; + static ETL_CONSTANT long long max = LLONG_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long long) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT long long statics_long_long::min; + + template + ETL_CONSTANT long long statics_long_long::max; + + template + ETL_CONSTANT int statics_long_long::bits; + + template + ETL_CONSTANT bool statics_long_long::is_signed; + + //*********************************** + // unsigned long long + template + struct statics_unsigned_long_long + { + typedef unsigned long value_type; + + static ETL_CONSTANT unsigned long long min = 0; + static ETL_CONSTANT unsigned long long max = ULLONG_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long long) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT unsigned long long statics_unsigned_long_long::min; + + template + ETL_CONSTANT unsigned long long statics_unsigned_long_long::max; + + template + ETL_CONSTANT int statics_unsigned_long_long::bits; + + template + ETL_CONSTANT bool statics_unsigned_long_long::is_signed; + +#if ETL_HAS_NATIVE_CHAR8_T + //*********************************** + // char8_t + template + struct statics_char8_t + { + typedef char8_t value_type; + + static ETL_CONSTANT char8_t min = (etl::is_signed::value) ? SCHAR_MIN : 0; + static ETL_CONSTANT char8_t max = (etl::is_signed::value) ? SCHAR_MAX : static_cast(UCHAR_MAX); + static ETL_CONSTANT int bits = CHAR_BIT; + static ETL_CONSTANT bool is_signed = etl::is_signed::value; + }; + + template + ETL_CONSTANT char8_t statics_char8_t::min; + + template + ETL_CONSTANT char8_t statics_char8_t::max; + + template + ETL_CONSTANT int statics_char8_t::bits; + + template + ETL_CONSTANT bool statics_char8_t::is_signed; +#endif + +#if ETL_HAS_NATIVE_CHAR16_T + //*********************************** + // char16_t + template + struct statics_char16_t + { + typedef char16_t value_type; + + static ETL_CONSTANT char16_t min = 0; + static ETL_CONSTANT char16_t max = 0xFFFFU; + static ETL_CONSTANT int bits = 16; + static ETL_CONSTANT bool is_signed = false; + }; + + template + ETL_CONSTANT char16_t statics_char16_t::min; + + template + ETL_CONSTANT char16_t statics_char16_t::max; + + template + ETL_CONSTANT int statics_char16_t::bits; + + template + ETL_CONSTANT bool statics_char16_t::is_signed; +#endif + +#if ETL_HAS_NATIVE_CHAR32_T + //*********************************** + // char32_t + template + struct statics_char32_t + { + typedef char32_t value_type; + + static ETL_CONSTANT char32_t min = 0; + static ETL_CONSTANT char32_t max = 0xFFFFFFFFU; + static ETL_CONSTANT int bits = 32; + static ETL_CONSTANT bool is_signed = false; + }; + + template + ETL_CONSTANT char32_t statics_char32_t::min; + + template + ETL_CONSTANT char32_t statics_char32_t::max; + + template + ETL_CONSTANT int statics_char32_t::bits; + + template + ETL_CONSTANT bool statics_char32_t::is_signed; +#endif + } + //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** @@ -57,249 +471,91 @@ namespace etl ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_signed_char<> { - typedef void value_type; - - static ETL_CONSTANT int min = 0; - static ETL_CONSTANT int max = 0; - static ETL_CONSTANT int bits = 0; - static ETL_CONSTANT bool is_signed = false; }; - ETL_CONSTANT int integral_limits::min; - ETL_CONSTANT int integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_unsigned_char<> { - typedef signed char value_type; - - static ETL_CONSTANT signed char min = SCHAR_MIN; - static ETL_CONSTANT signed char max = SCHAR_MAX; - static ETL_CONSTANT int bits = CHAR_BIT; - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - ETL_CONSTANT signed char integral_limits::min; - ETL_CONSTANT signed char integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** + template <> - struct integral_limits - { - typedef unsigned char value_type; - - static ETL_CONSTANT unsigned char min = 0; - static ETL_CONSTANT unsigned char max = UCHAR_MAX; - static ETL_CONSTANT int bits = CHAR_BIT; - static ETL_CONSTANT bool is_signed = etl::is_signed::value; - }; - - ETL_CONSTANT unsigned char integral_limits::min; - ETL_CONSTANT unsigned char integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - - //*************************************************************************** - ///\ingroup integral_limits - //*************************************************************************** -#if defined(ETL_COMPILER_MICROSOFT) - #pragma warning(push) - #pragma warning(disable : 4309) -#endif - template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_char<> { typedef char value_type; - - static ETL_CONSTANT char min = (etl::is_signed::value) ? SCHAR_MIN : 0; - static ETL_CONSTANT char max = (etl::is_signed::value) ? SCHAR_MAX : static_cast(UCHAR_MAX); - static ETL_CONSTANT int bits = CHAR_BIT; - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - ETL_CONSTANT char integral_limits::min; - ETL_CONSTANT char integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - -#if defined(ETL_COMPILER_MICROSOFT) - #pragma warning(pop) -#endif - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_short<> { - typedef short value_type; - - static ETL_CONSTANT short min = SHRT_MIN; - static ETL_CONSTANT short max = SHRT_MAX; - static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(short) / sizeof(char)); - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - ETL_CONSTANT short integral_limits::min; - ETL_CONSTANT short integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_unsigned_short<> { - typedef unsigned short value_type; - - static ETL_CONSTANT unsigned short min = 0; - static ETL_CONSTANT unsigned short max = USHRT_MAX; - static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned short) / sizeof(char)); - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - ETL_CONSTANT unsigned short integral_limits::min; - ETL_CONSTANT unsigned short integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_int<> { - typedef int value_type; - - static ETL_CONSTANT int min = INT_MIN; - static ETL_CONSTANT int max = INT_MAX; - static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(int) / sizeof(char)); - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - ETL_CONSTANT int integral_limits::min; - ETL_CONSTANT int integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_unsigned_int<> { - typedef unsigned int value_type; - - static ETL_CONSTANT unsigned int min = 0; - static ETL_CONSTANT unsigned int max = UINT_MAX; - static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned int) / sizeof(char)); - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - ETL_CONSTANT unsigned int integral_limits::min; - ETL_CONSTANT unsigned int integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_long<> { - typedef long value_type; - - static ETL_CONSTANT long min = LONG_MIN; - static ETL_CONSTANT long max = LONG_MAX; - static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long) / sizeof(char)); - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - ETL_CONSTANT long integral_limits::min; - ETL_CONSTANT long integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_unsigned_long<> { - typedef unsigned long value_type; - - static ETL_CONSTANT unsigned long min = 0; - static ETL_CONSTANT unsigned long max = ULONG_MAX; - static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long) / sizeof(char)); - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - ETL_CONSTANT unsigned long integral_limits::min; - ETL_CONSTANT unsigned long integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - -#ifndef LLONG_MAX -#define LLONG_MAX 9223372036854775807LL -#endif - -#ifndef LLONG_MIN -#define LLONG_MIN (-LLONG_MAX - 1LL) -#endif - -#ifndef ULLONG_MAX -#define ULLONG_MAX 18446744073709551615ULL -#endif - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits - { - typedef long long value_type; - - static ETL_CONSTANT long long min = LLONG_MIN; - static ETL_CONSTANT long long max = LLONG_MAX; - static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long long) / sizeof(char)); - static ETL_CONSTANT bool is_signed = etl::is_signed::value; + struct integral_limits : public private_integral_limits::statics_long_long<> + { }; - ETL_CONSTANT long long integral_limits::min; - ETL_CONSTANT long long integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; - //*************************************************************************** ///\ingroup integral_limits //*************************************************************************** template <> - struct integral_limits + struct integral_limits : public private_integral_limits::statics_unsigned_long_long<> { - typedef unsigned long long value_type; - - static ETL_CONSTANT unsigned long long min = 0; - static ETL_CONSTANT unsigned long long max = ULLONG_MAX; - static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long long) / sizeof(char)); - static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; - - ETL_CONSTANT unsigned long long integral_limits::min; - ETL_CONSTANT unsigned long long integral_limits::max; - ETL_CONSTANT int integral_limits::bits; - ETL_CONSTANT bool integral_limits::is_signed; } #include "private/minmax_pop.h" diff --git a/include/etl/limits.h b/include/etl/limits.h index 1aced396..ae54da04 100644 --- a/include/etl/limits.h +++ b/include/etl/limits.h @@ -115,155 +115,644 @@ namespace etl denorm_present = 1 }; - template - class etl_integral_limits + namespace private_limits { - public: + //********************************* + // Integral limits common + template + class integral_limits_common + { + public: - 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; - }; + 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; + }; - template - ETL_CONSTANT bool etl_integral_limits::is_specialized; + template + ETL_CONSTANT bool integral_limits_common::is_specialized; - template - ETL_CONSTANT bool etl_integral_limits::is_integer; + template + ETL_CONSTANT bool integral_limits_common::is_integer; - template - ETL_CONSTANT bool etl_integral_limits::is_exact; + template + ETL_CONSTANT bool integral_limits_common::is_exact; - template - ETL_CONSTANT int etl_integral_limits::max_digits10; + template + ETL_CONSTANT int integral_limits_common::max_digits10; - template - ETL_CONSTANT int etl_integral_limits::radix; + template + ETL_CONSTANT int integral_limits_common::radix; - template - ETL_CONSTANT int etl_integral_limits::min_exponent; + template + ETL_CONSTANT int integral_limits_common::min_exponent; - template - ETL_CONSTANT int etl_integral_limits::min_exponent10; + template + ETL_CONSTANT int integral_limits_common::min_exponent10; - template - ETL_CONSTANT int etl_integral_limits::max_exponent; + template + ETL_CONSTANT int integral_limits_common::max_exponent; - template - ETL_CONSTANT int etl_integral_limits::max_exponent10; + template + ETL_CONSTANT int integral_limits_common::max_exponent10; - template - ETL_CONSTANT bool etl_integral_limits::has_infinity; + template + ETL_CONSTANT bool integral_limits_common::has_infinity; - template - ETL_CONSTANT bool etl_integral_limits::has_quiet_NaN; + template + ETL_CONSTANT bool integral_limits_common::has_quiet_NaN; - template - ETL_CONSTANT bool etl_integral_limits::has_signaling_NaN; + template + ETL_CONSTANT bool integral_limits_common::has_signaling_NaN; - template - ETL_CONSTANT bool etl_integral_limits::has_denorm_loss; - - template - ETL_CONSTANT bool etl_integral_limits::is_iec559; - - template - ETL_CONSTANT bool etl_integral_limits::is_bounded; - - template - ETL_CONSTANT bool etl_integral_limits::traps; - - template - ETL_CONSTANT bool etl_integral_limits::tinyness_before; + template + ETL_CONSTANT bool integral_limits_common::has_denorm_loss; - template - ETL_CONSTANT float_denorm_style etl_integral_limits::has_denorm; - - template - ETL_CONSTANT float_round_style etl_integral_limits::round_style; + template + ETL_CONSTANT bool integral_limits_common::is_iec559; - template - class etl_floating_point_limits - { - public: + template + ETL_CONSTANT bool integral_limits_common::is_bounded; - 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; + template + ETL_CONSTANT bool integral_limits_common::traps; - static float round_error() { return float(0.5); } - }; + template + ETL_CONSTANT bool integral_limits_common::tinyness_before; - template - ETL_CONSTANT bool etl_floating_point_limits::is_specialized; + template + ETL_CONSTANT float_denorm_style integral_limits_common::has_denorm; - template - ETL_CONSTANT bool etl_floating_point_limits::is_integer; + template + ETL_CONSTANT float_round_style integral_limits_common::round_style; - template - ETL_CONSTANT bool etl_floating_point_limits::is_exact; + //********************************* + // bool + template + struct integral_limits_bool + { + 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; + }; - template - ETL_CONSTANT int etl_floating_point_limits::radix; + template + ETL_CONSTANT int integral_limits_bool::digits; - template - ETL_CONSTANT bool etl_floating_point_limits::has_infinity; + template + ETL_CONSTANT int integral_limits_bool::digits10; - template - ETL_CONSTANT bool etl_floating_point_limits::has_quiet_NaN; + template + ETL_CONSTANT bool integral_limits_bool::is_signed; - template - ETL_CONSTANT bool etl_floating_point_limits::has_signaling_NaN; + template + ETL_CONSTANT bool integral_limits_bool::is_modulo; - template - ETL_CONSTANT bool etl_floating_point_limits::has_denorm_loss; + //********************************* + // char + template + struct integral_limits_char + { + 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 = etl::is_unsigned::value; + }; - template - ETL_CONSTANT bool etl_floating_point_limits::is_iec559; + template + ETL_CONSTANT int integral_limits_char::digits; - template - ETL_CONSTANT bool etl_floating_point_limits::is_bounded; - - template - ETL_CONSTANT bool etl_floating_point_limits::traps; - - template - ETL_CONSTANT bool etl_floating_point_limits::tinyness_before; - - template - ETL_CONSTANT float_denorm_style etl_floating_point_limits::has_denorm; - - template - ETL_CONSTANT float_round_style etl_floating_point_limits::round_style; + template + ETL_CONSTANT int integral_limits_char::digits10; + + template + ETL_CONSTANT bool integral_limits_char::is_signed; + + template + ETL_CONSTANT bool integral_limits_char::is_modulo; + + //********************************* + // unsigned char + template + struct integral_limits_unsigned_char + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned char)); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; + }; + + template + ETL_CONSTANT int integral_limits_unsigned_char::digits; + + template + ETL_CONSTANT int integral_limits_unsigned_char::digits10; + + template + ETL_CONSTANT bool integral_limits_unsigned_char::is_signed; + + template + ETL_CONSTANT bool integral_limits_unsigned_char::is_modulo; + + //********************************* + // signed char + template + struct integral_limits_signed_char + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char)) - 1; + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; + }; + + template + ETL_CONSTANT int integral_limits_signed_char::digits; + + template + ETL_CONSTANT int integral_limits_signed_char::digits10; + + template + ETL_CONSTANT bool integral_limits_signed_char::is_signed; + + template + ETL_CONSTANT bool integral_limits_signed_char::is_modulo; + +#if ETL_HAS_NATIVE_CHAR8_T + //********************************* + // char8_t + template + struct integral_limits_char8_t + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char8_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 = false; + }; + + template + ETL_CONSTANT int integral_limits_char8_t::digits; + + template + ETL_CONSTANT int integral_limits_char8_t::digits10; + + template + ETL_CONSTANT bool integral_limits_char8_t::is_signed; + + template + ETL_CONSTANT bool integral_limits_char8_t::is_modulo; +#endif + +#if ETL_HAS_NATIVE_CHAR16_T + //********************************* + // char16_t + template + struct integral_limits_char16_t + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char16_t)); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; + }; + + template + ETL_CONSTANT int integral_limits_char16_t::digits; + + template + ETL_CONSTANT int integral_limits_char16_t::digits10; + + template + ETL_CONSTANT bool integral_limits_char16_t::is_signed; + + template + ETL_CONSTANT bool integral_limits_char16_t::is_modulo; +#endif + +#if ETL_HAS_NATIVE_CHAR32_T + //********************************* + // char32_t + template + struct integral_limits_char32_t + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char32_t)); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; + }; + + template + ETL_CONSTANT int integral_limits_char32_t::digits; + + template + ETL_CONSTANT int integral_limits_char32_t::digits10; + + template + ETL_CONSTANT bool integral_limits_char32_t::is_signed; + + template + ETL_CONSTANT bool integral_limits_char32_t::is_modulo; +#endif + + //********************************* + // wchar_t + template + struct integral_limits_wchar_t + { + 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; + }; + + template + ETL_CONSTANT int integral_limits_wchar_t::digits; + + template + ETL_CONSTANT int integral_limits_wchar_t::digits10; + + template + ETL_CONSTANT bool integral_limits_wchar_t::is_signed; + + template + ETL_CONSTANT bool integral_limits_wchar_t::is_modulo; + + //********************************* + // short + template + struct integral_limits_short + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(short)) - 1; + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; + }; + + template + ETL_CONSTANT int integral_limits_short::digits; + + template + ETL_CONSTANT int integral_limits_short::digits10; + + template + ETL_CONSTANT bool integral_limits_short::is_signed; + + template + ETL_CONSTANT bool integral_limits_short::is_modulo; + + //********************************* + // unsigned short + template + struct integral_limits_unsigned_short + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned short)); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; + }; + + template + ETL_CONSTANT int integral_limits_unsigned_short::digits; + + template + ETL_CONSTANT int integral_limits_unsigned_short::digits10; + + template + ETL_CONSTANT bool integral_limits_unsigned_short::is_signed; + + template + ETL_CONSTANT bool integral_limits_unsigned_short::is_modulo; + + //********************************* + // int + template + struct integral_limits_int + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(int)) - 1; + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; + }; + + template + ETL_CONSTANT int integral_limits_int::digits; + + template + ETL_CONSTANT int integral_limits_int::digits10; + + template + ETL_CONSTANT bool integral_limits_int::is_signed; + + template + ETL_CONSTANT bool integral_limits_int::is_modulo; + + //********************************* + // unsigned int + template + struct integral_limits_unsigned_int + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned int)); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; + }; + + template + ETL_CONSTANT int integral_limits_unsigned_int::digits; + + template + ETL_CONSTANT int integral_limits_unsigned_int::digits10; + + template + ETL_CONSTANT bool integral_limits_unsigned_int::is_signed; + + template + ETL_CONSTANT bool integral_limits_unsigned_int::is_modulo; + + //********************************* + // long + template + struct integral_limits_long + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(long)) - 1; + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; + }; + + template + ETL_CONSTANT int integral_limits_long::digits; + + template + ETL_CONSTANT int integral_limits_long::digits10; + + template + ETL_CONSTANT bool integral_limits_long::is_signed; + + template + ETL_CONSTANT bool integral_limits_long::is_modulo; + + //********************************* + // unsigned long + template + struct integral_limits_unsigned_long + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned long)); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; + }; + + template + ETL_CONSTANT int integral_limits_unsigned_long::digits; + + template + ETL_CONSTANT int integral_limits_unsigned_long::digits10; + + template + ETL_CONSTANT bool integral_limits_unsigned_long::is_signed; + + template + ETL_CONSTANT bool integral_limits_unsigned_long::is_modulo; + + //********************************* + // long long + template + struct integral_limits_long_long + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(long long)) - 1; + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = true; + static ETL_CONSTANT bool is_modulo = false; + }; + + template + ETL_CONSTANT int integral_limits_long_long::digits; + + template + ETL_CONSTANT int integral_limits_long_long::digits10; + + template + ETL_CONSTANT bool integral_limits_long_long::is_signed; + + template + ETL_CONSTANT bool integral_limits_long_long::is_modulo; + + //********************************* + // unsigned long long + template + struct integral_limits_unsigned_long_long + { + static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned long long)); + static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits); + static ETL_CONSTANT bool is_signed = false; + static ETL_CONSTANT bool is_modulo = true; + }; + + template + ETL_CONSTANT int integral_limits_unsigned_long_long::digits; + + template + ETL_CONSTANT int integral_limits_unsigned_long_long::digits10; + + template + ETL_CONSTANT bool integral_limits_unsigned_long_long::is_signed; + + template + ETL_CONSTANT bool integral_limits_unsigned_long_long::is_modulo; + + //********************************* + // Floating point limits common + template + class floating_point_limits_common + { + public: + + 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); } + }; + + template + ETL_CONSTANT bool floating_point_limits_common::is_specialized; + + template + ETL_CONSTANT bool floating_point_limits_common::is_integer; + + template + ETL_CONSTANT bool floating_point_limits_common::is_exact; + + template + ETL_CONSTANT int floating_point_limits_common::radix; + + template + ETL_CONSTANT bool floating_point_limits_common::has_infinity; + + template + ETL_CONSTANT bool floating_point_limits_common::has_quiet_NaN; + + template + ETL_CONSTANT bool floating_point_limits_common::has_signaling_NaN; + + template + ETL_CONSTANT bool floating_point_limits_common::has_denorm_loss; + + template + ETL_CONSTANT bool floating_point_limits_common::is_iec559; + + template + ETL_CONSTANT bool floating_point_limits_common::is_bounded; + + template + ETL_CONSTANT bool floating_point_limits_common::traps; + + template + ETL_CONSTANT bool floating_point_limits_common::tinyness_before; + + template + ETL_CONSTANT float_denorm_style floating_point_limits_common::has_denorm; + + template + ETL_CONSTANT float_round_style floating_point_limits_common::round_style; + + //********************************* + // float + template + struct floating_point_limits_float + { + 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 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; + }; + + template + ETL_CONSTANT int floating_point_limits_float::digits; + + template + ETL_CONSTANT int floating_point_limits_float::digits10; + + template + ETL_CONSTANT int floating_point_limits_float::max_digits10; + + template + ETL_CONSTANT int floating_point_limits_float::min_exponent; + + template + ETL_CONSTANT int floating_point_limits_float::min_exponent10; + + template + ETL_CONSTANT int floating_point_limits_float::max_exponent; + + template + ETL_CONSTANT int floating_point_limits_float::max_exponent10; + + //********************************* + // double + template + struct floating_point_limits_double + { + 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 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; + }; + + template + ETL_CONSTANT int floating_point_limits_double::digits; + + template + ETL_CONSTANT int floating_point_limits_double::digits10; + + template + ETL_CONSTANT int floating_point_limits_double::max_digits10; + + template + ETL_CONSTANT int floating_point_limits_double::min_exponent; + + template + ETL_CONSTANT int floating_point_limits_double::min_exponent10; + + template + ETL_CONSTANT int floating_point_limits_double::max_exponent; + + template + ETL_CONSTANT int floating_point_limits_double::max_exponent10; + + //********************************* + // long double + template + struct floating_point_limits_long_double + { + 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 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; + }; + + template + ETL_CONSTANT int floating_point_limits_long_double::digits; + + template + ETL_CONSTANT int floating_point_limits_long_double::digits10; + + template + ETL_CONSTANT int floating_point_limits_long_double::max_digits10; + + template + ETL_CONSTANT int floating_point_limits_long_double::min_exponent; + + template + ETL_CONSTANT int floating_point_limits_long_double::min_exponent10; + + template + ETL_CONSTANT int floating_point_limits_long_double::max_exponent; + + template + ETL_CONSTANT int floating_point_limits_long_double::max_exponent10; + } //*************************************************************************** // Default @@ -279,18 +768,14 @@ namespace etl template class numeric_limits : public numeric_limits { }; - //*************************************************************************** + //*********************************** // bool template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_bool<> { public: - 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 ETL_CONSTEXPR bool min() { return false; } static ETL_CONSTEXPR bool max() { return true; } static ETL_CONSTEXPR bool lowest() { return false; } @@ -302,23 +787,14 @@ namespace etl static ETL_CONSTEXPR bool signaling_NaN() { return false; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // char template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_char<> { public: - 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 ETL_CONSTEXPR char min() { return char(CHAR_MIN); } static ETL_CONSTEXPR char max() { return char(CHAR_MAX); } static ETL_CONSTEXPR char lowest() { return char(CHAR_MIN); } @@ -330,23 +806,14 @@ namespace etl static ETL_CONSTEXPR char signaling_NaN() { return 0; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // unsigned char template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_unsigned_char<> { public: - 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 ETL_CONSTEXPR unsigned char min() { return 0U; } static ETL_CONSTEXPR unsigned char max() { return UCHAR_MAX; } static ETL_CONSTEXPR unsigned char lowest() { return 0U; } @@ -358,23 +825,14 @@ namespace etl static ETL_CONSTEXPR unsigned char signaling_NaN() { return 0U; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // signed char template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_signed_char<> { public: - 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 ETL_CONSTEXPR signed char min() { return SCHAR_MIN; } static ETL_CONSTEXPR signed char max() { return SCHAR_MAX; } static ETL_CONSTEXPR signed char lowest() { return SCHAR_MIN; } @@ -386,24 +844,15 @@ namespace etl static ETL_CONSTEXPR signed char signaling_NaN() { return 0; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - #if ETL_HAS_NATIVE_CHAR8_T //*************************************************************************** // char8_t template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_char8_t<> { public: - - static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char8_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 = false; - + static ETL_CONSTEXPR char8_t min() { return char8_t(CHAR_MIN); } static ETL_CONSTEXPR char8_t max() { return char8_t(CHAR_MAX); } static ETL_CONSTEXPR char8_t lowest() { return char8_t(CHAR_MIN); } @@ -414,26 +863,17 @@ namespace etl static ETL_CONSTEXPR char8_t quiet_NaN() { return 0; } static ETL_CONSTEXPR char8_t signaling_NaN() { return 0; } }; - - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; #endif #if ETL_HAS_NATIVE_CHAR16_T //*************************************************************************** // char16_t template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_char16_t<> { public: - 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 ETL_CONSTEXPR char16_t min() { return 0U; } static ETL_CONSTEXPR char16_t max() { return UINT_LEAST16_MAX; } static ETL_CONSTEXPR char16_t lowest() { return 0U; } @@ -444,26 +884,17 @@ namespace etl static ETL_CONSTEXPR char16_t quiet_NaN() { return 0U; } static ETL_CONSTEXPR char16_t signaling_NaN() { return 0U; } }; - - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; #endif #if ETL_HAS_NATIVE_CHAR32_T //*************************************************************************** // char32_t template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_char32_t<> { public: - 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 ETL_CONSTEXPR char32_t min() { return 0U; } static ETL_CONSTEXPR char32_t max() { return UINT_LEAST32_MAX; } static ETL_CONSTEXPR char32_t lowest() { return 0U; } @@ -474,24 +905,16 @@ namespace etl static ETL_CONSTEXPR char32_t quiet_NaN() { return 0U; } static ETL_CONSTEXPR char32_t signaling_NaN() { return 0U; } }; - - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; #endif //*************************************************************************** // wchar_t template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_wchar_t<> { public: - 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 ETL_CONSTEXPR wchar_t min() { return WCHAR_MIN; } static ETL_CONSTEXPR wchar_t max() { return WCHAR_MAX; } static ETL_CONSTEXPR wchar_t lowest() { return WCHAR_MIN; } @@ -503,23 +926,14 @@ namespace etl static ETL_CONSTEXPR wchar_t signaling_NaN() { return wchar_t(0); } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // short template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_short<> { public: - 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 ETL_CONSTEXPR short min() { return SHRT_MIN; } static ETL_CONSTEXPR short max() { return SHRT_MAX; } static ETL_CONSTEXPR short lowest() { return SHRT_MIN; } @@ -531,23 +945,14 @@ namespace etl static ETL_CONSTEXPR short signaling_NaN() { return 0; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // unsigned short template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_unsigned_short<> { public: - 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 ETL_CONSTEXPR unsigned short min() { return 0U; } static ETL_CONSTEXPR unsigned short max() { return USHRT_MAX; } static ETL_CONSTEXPR unsigned short lowest() { return 0U; } @@ -559,23 +964,14 @@ namespace etl static ETL_CONSTEXPR unsigned short signaling_NaN() { return 0U; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // int template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_int<> { public: - 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 ETL_CONSTEXPR int min() { return INT_MIN; } static ETL_CONSTEXPR int max() { return INT_MAX; } static ETL_CONSTEXPR int lowest() { return INT_MIN; } @@ -587,23 +983,14 @@ namespace etl static ETL_CONSTEXPR int signaling_NaN() { return 0; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // unsigned int template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_unsigned_int<> { public: - 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 ETL_CONSTEXPR unsigned int min() { return 0U; } static ETL_CONSTEXPR unsigned int max() { return UINT_MAX; } static ETL_CONSTEXPR unsigned int lowest() { return 0U; } @@ -615,23 +1002,14 @@ namespace etl static ETL_CONSTEXPR unsigned int signaling_NaN() { return 0U; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // long template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_long<> { public: - 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 ETL_CONSTEXPR long min() { return LONG_MIN; } static ETL_CONSTEXPR long max() { return LONG_MAX; } static ETL_CONSTEXPR long lowest() { return LONG_MIN; } @@ -643,23 +1021,14 @@ namespace etl static ETL_CONSTEXPR long signaling_NaN() { return 0; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // unsigned long template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_unsigned_long<> { public: - 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 ETL_CONSTEXPR unsigned long min() { return 0U; } static ETL_CONSTEXPR unsigned long max() { return ULONG_MAX; } static ETL_CONSTEXPR unsigned long lowest() { return 0U; } @@ -671,23 +1040,14 @@ namespace etl static ETL_CONSTEXPR unsigned long signaling_NaN() { return 0U; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // long long template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_long_long<> { public: - 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 ETL_CONSTEXPR long long min() { return LLONG_MIN; } static ETL_CONSTEXPR long long max() { return LLONG_MAX; } static ETL_CONSTEXPR long long lowest() { return LLONG_MIN; } @@ -699,23 +1059,14 @@ namespace etl static ETL_CONSTEXPR long long signaling_NaN() { return 0; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // unsigned long long template<> - class numeric_limits : public etl_integral_limits<> + class numeric_limits : public private_limits::integral_limits_common<>, + public private_limits::integral_limits_unsigned_long_long<> { public: - 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 ETL_CONSTEXPR unsigned long long min() { return 0U; } static ETL_CONSTEXPR unsigned long long max() { return ULLONG_MAX; } static ETL_CONSTEXPR unsigned long long lowest() { return 0U; } @@ -727,15 +1078,11 @@ namespace etl static ETL_CONSTEXPR unsigned long long signaling_NaN() { return 0U; } }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT bool numeric_limits::is_signed; - ETL_CONSTANT bool numeric_limits::is_modulo; - //*************************************************************************** // float template<> - class numeric_limits : public etl_floating_point_limits<> + class numeric_limits : public private_limits::floating_point_limits_common<>, + public private_limits::floating_point_limits_float<> { public: @@ -747,30 +1094,13 @@ namespace etl static ETL_CONSTEXPR float infinity() { return HUGE_VALF; } static float quiet_NaN() { return ETL_NANF; } static float signaling_NaN() { return ETL_NANF; } - - 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 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; }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT int numeric_limits::max_digits10; - - ETL_CONSTANT int numeric_limits::min_exponent; - ETL_CONSTANT int numeric_limits::min_exponent10; - ETL_CONSTANT int numeric_limits::max_exponent; - ETL_CONSTANT int numeric_limits::max_exponent10; - //*************************************************************************** // double template<> - class numeric_limits : public etl_floating_point_limits<> + class numeric_limits : public private_limits::floating_point_limits_common<>, + public private_limits::floating_point_limits_double<> { public: @@ -782,30 +1112,13 @@ namespace etl static ETL_CONSTEXPR double infinity() { return HUGE_VAL; } static double quiet_NaN() { return ETL_NAN; } static double signaling_NaN() { return ETL_NAN; } - - 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 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; }; - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT int numeric_limits::max_digits10; - - ETL_CONSTANT int numeric_limits::min_exponent; - ETL_CONSTANT int numeric_limits::min_exponent10; - ETL_CONSTANT int numeric_limits::max_exponent; - ETL_CONSTANT int numeric_limits::max_exponent10; - //*************************************************************************** // long double template<> - class numeric_limits : public etl_floating_point_limits<> + class numeric_limits : public private_limits::floating_point_limits_common<>, + public private_limits::floating_point_limits_long_double<> { public: @@ -817,25 +1130,7 @@ namespace etl static ETL_CONSTEXPR long double infinity() { return HUGE_VALL; } static long double quiet_NaN() { return ETL_NANL; } static long double signaling_NaN() { return ETL_NANL; } - - 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 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; }; - - ETL_CONSTANT int numeric_limits::digits; - ETL_CONSTANT int numeric_limits::digits10; - ETL_CONSTANT int numeric_limits::max_digits10; - - ETL_CONSTANT int numeric_limits::min_exponent; - ETL_CONSTANT int numeric_limits::min_exponent10; - ETL_CONSTANT int numeric_limits::max_exponent; - ETL_CONSTANT int numeric_limits::max_exponent10; } #else @@ -860,10 +1155,15 @@ namespace etl denorm_present = std::denorm_present }; +#if ETL_USING_CPP11 + template + using numeric_limits = std::numeric_limits; +#else template class numeric_limits : public std::numeric_limits { }; +#endif } #endif diff --git a/include/etl/parameter_pack.h b/include/etl/parameter_pack.h index e5760453..7f30a82c 100644 --- a/include/etl/parameter_pack.h +++ b/include/etl/parameter_pack.h @@ -121,9 +121,19 @@ namespace etl using type_from_index_t = typename type_from_index::type; }; + //*********************************** template using parameter_pack_t = typename etl::parameter_pack::template type_from_index_t; + //*********************************** + template + constexpr size_t parameter_pack::size; + + //*********************************** + template + template + constexpr size_t parameter_pack::template index_of_type::value; + #if ETL_USING_CPP17 template inline constexpr size_t parameter_pack_v = etl::parameter_pack::template index_of_type::value; diff --git a/include/etl/private/bitset_legacy.h b/include/etl/private/bitset_legacy.h index 5d785152..e03135ce 100644 --- a/include/etl/private/bitset_legacy.h +++ b/include/etl/private/bitset_legacy.h @@ -183,6 +183,15 @@ namespace etl return p_bitset->test(position); } + //******************************* + /// Copy constructor. + //******************************* + bit_reference(const bit_reference& other) + : p_bitset(other.p_bitset) + , position(other.position) + { + } + //******************************* /// Assignment operator. //******************************* diff --git a/include/etl/private/bitset_new.h b/include/etl/private/bitset_new.h index 9352d2b9..2b01ecc3 100644 --- a/include/etl/private/bitset_new.h +++ b/include/etl/private/bitset_new.h @@ -810,7 +810,7 @@ namespace etl //*************************************************************************** template ::bits == Active_Bits> class bitset; @@ -819,7 +819,7 @@ namespace etl /// Just defines 'npos'. //*************************************************************************** template <> - class bitset<0U, void, true> : public bitset_constants<> + class bitset<0U, char, true> : public bitset_constants<> { }; @@ -827,7 +827,7 @@ namespace etl /// Specialisation for zero bits. //*************************************************************************** template <> - class bitset<0U, void, false> : public bitset_constants<> + class bitset<0U, char, false> : public bitset_constants<> { }; @@ -866,6 +866,15 @@ namespace etl friend class bitset; + //******************************* + /// Copy constructor. + //******************************* + ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT + : p_bitset(other.p_bitset) + , position(other.position) + { + } + //******************************* /// Conversion operator. //******************************* @@ -892,15 +901,6 @@ namespace etl return *this; } - //******************************* - /// Copy constructor. - //******************************* - ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT - : p_bitset(other.p_bitset) - , position(other.position) - { - } - //******************************* /// Flip the bit. //******************************* @@ -1751,6 +1751,15 @@ namespace etl friend class bitset; + //******************************* + /// Copy constructor. + //******************************* + ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT + : p_bitset(other.p_bitset) + , position(other.position) + { + } + //******************************* /// Conversion operator. //******************************* @@ -1777,15 +1786,6 @@ namespace etl return *this; } - //******************************* - /// Copy constructor. - //******************************* - ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT - : p_bitset(other.p_bitset) - , position(other.position) - { - } - //******************************* /// Flip the bit. //******************************* @@ -2448,7 +2448,7 @@ namespace etl { //*************************************************************************** template ::bits == Active_Bits> class bitset_ext; @@ -2457,7 +2457,7 @@ namespace etl /// Just defines 'npos'. //*************************************************************************** template <> - class bitset_ext<0U, void, true> : public bitset_constants<> + class bitset_ext<0U, char, true> : public bitset_constants<> { }; @@ -2465,7 +2465,7 @@ namespace etl /// Specialisation for zero bits. //*************************************************************************** template <> - class bitset_ext<0U, void, false> : public bitset_constants<> + class bitset_ext<0U, char, false> : public bitset_constants<> { }; @@ -2506,6 +2506,15 @@ namespace etl friend class bitset_ext; + //******************************* + /// Copy constructor. + //******************************* + ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT + : p_bitset(other.p_bitset) + , position(other.position) + { + } + //******************************* /// Conversion operator. //******************************* @@ -3381,6 +3390,15 @@ namespace etl friend class bitset_ext; + //******************************* + /// Copy constructor + //******************************* + ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT + : p_bitset(other.p_bitset) + , position(other.position) + { + } + //******************************* /// Conversion operator. //******************************* diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 5d344b5c..76a90c62 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -1352,10 +1352,10 @@ namespace etl /// in which every recursive instantiation of `visit_result_helper` appends /// more elements and give it a pass through `common_type_t`. //*************************************************************************** - template