mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
#1126 to_arithmetic does not compile on C++98
This commit is contained in:
parent
7f53572b53
commit
0e6e961039
@ -64,16 +64,14 @@ namespace etl
|
||||
// For signed types.
|
||||
// Returns the result as the unsigned type.
|
||||
//***************************************************************************
|
||||
#if ETL_USING_CPP11
|
||||
template <typename T, typename TReturn = typename etl::make_unsigned<T>::type>
|
||||
#else
|
||||
template <typename T, typename TReturn>
|
||||
#endif
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR
|
||||
typename etl::enable_if<etl::is_signed<T>::value, TReturn>::type
|
||||
typename etl::enable_if<etl::is_signed<T>::value, typename etl::make_unsigned<T>::type>::type
|
||||
absolute_unsigned(T value) ETL_NOEXCEPT
|
||||
{
|
||||
typedef typename etl::make_unsigned<T>::type TReturn;
|
||||
|
||||
return (value == etl::integral_limits<T>::min) ? (etl::integral_limits<TReturn>::max / 2U) + 1U
|
||||
: (value < T(0)) ? TReturn(-value) : TReturn(value);
|
||||
}
|
||||
|
||||
@ -139,9 +139,11 @@ namespace etl
|
||||
/// Assign from etl::unexpected.
|
||||
//*******************************************
|
||||
ETL_CONSTEXPR14
|
||||
etl::unexpected<TError>& operator =(const etl::unexpected<TError>& rhs)
|
||||
etl::unexpected<TError>& operator =(const etl::unexpected<TError>& rhs)
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
|
||||
#endif
|
||||
|
||||
error_value = rhs.error_value;
|
||||
return *this;
|
||||
@ -443,7 +445,9 @@ namespace etl
|
||||
//*******************************************
|
||||
expected& operator =(const unexpected_type& ue)
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
|
||||
#endif
|
||||
|
||||
storage.template emplace<Error_Type>(ue.error());
|
||||
|
||||
@ -843,7 +847,9 @@ namespace etl
|
||||
//*******************************************
|
||||
expected& operator =(const unexpected_type& ue)
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
|
||||
#endif
|
||||
|
||||
storage.template emplace<Error_Type>(ue.error());
|
||||
return *this;
|
||||
|
||||
@ -535,5 +535,57 @@ namespace
|
||||
CHECK_EQUAL(5, lcm5);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_absolute)
|
||||
{
|
||||
CHECK_EQUAL(int16_t(0), etl::absolute(int16_t(0)));
|
||||
CHECK_EQUAL(int16_t(32767), etl::absolute(int16_t(32767)));
|
||||
CHECK_EQUAL(int16_t(32767), etl::absolute(int16_t(-32767)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_absolute_constexpr)
|
||||
{
|
||||
constexpr int16_t absolute1 = etl::absolute(int16_t(0));
|
||||
constexpr int16_t absolute2 = etl::absolute(int16_t(32767));
|
||||
constexpr int16_t absolute3 = etl::absolute(int16_t(-32767));
|
||||
|
||||
CHECK_EQUAL(int16_t(0), absolute1);
|
||||
CHECK_EQUAL(int16_t(32767), absolute2);
|
||||
CHECK_EQUAL(int16_t(32767), absolute3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_absolute_unsigned)
|
||||
{
|
||||
CHECK_EQUAL(uint16_t(0), etl::absolute_unsigned(int16_t(0)));
|
||||
CHECK_EQUAL(uint16_t(32767), etl::absolute_unsigned(int16_t(32767)));
|
||||
CHECK_EQUAL(uint16_t(32767), etl::absolute_unsigned(int16_t(-32767)));
|
||||
CHECK_EQUAL(uint16_t(32768), etl::absolute_unsigned(int16_t(-32768)));
|
||||
|
||||
CHECK_EQUAL(uint16_t(0), etl::absolute_unsigned(uint16_t(0)));
|
||||
CHECK_EQUAL(uint16_t(65535), etl::absolute_unsigned(uint16_t(65535)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_absolute_unsigned_constexpr)
|
||||
{
|
||||
constexpr uint16_t absolute1 = etl::absolute(int16_t(0));
|
||||
constexpr uint16_t absolute2 = etl::absolute(int16_t(32767));
|
||||
constexpr uint16_t absolute3 = etl::absolute(int16_t(-32767));
|
||||
constexpr uint16_t absolute4 = etl::absolute(int16_t(-32768));
|
||||
|
||||
CHECK_EQUAL(uint16_t(0), absolute1);
|
||||
CHECK_EQUAL(uint16_t(32767), absolute2);
|
||||
CHECK_EQUAL(uint16_t(32767), absolute3);
|
||||
CHECK_EQUAL(uint16_t(32768), absolute4);
|
||||
|
||||
constexpr uint16_t absolute5 = etl::absolute(uint16_t(0));
|
||||
constexpr uint16_t absolute6 = etl::absolute(uint16_t(65535));
|
||||
|
||||
CHECK_EQUAL(uint16_t(0), absolute5);
|
||||
CHECK_EQUAL(uint16_t(65535), absolute6);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -266,7 +266,6 @@ namespace
|
||||
|
||||
CHECK(!etl::to_arithmetic<uint64_t>(uint64_overflow_max.c_str(), uint64_overflow_max.size(), etl::bin));
|
||||
|
||||
|
||||
CHECK_EQUAL(etl::to_arithmetic_status::Overflow, etl::to_arithmetic<int8_t>(int8_overflow_max.c_str(), int8_overflow_max.size(), etl::bin).error());
|
||||
CHECK_EQUAL(etl::to_arithmetic_status::Overflow, etl::to_arithmetic<int8_t>(int8_overflow_min.c_str(), int8_overflow_min.size(), etl::bin).error());
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user