mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Modified return types
This commit is contained in:
parent
f1d80ba577
commit
4bc8d00737
@ -42,61 +42,56 @@ SOFTWARE.
|
||||
//*****************************************************************************
|
||||
namespace etl
|
||||
{
|
||||
struct compare_types
|
||||
{
|
||||
typedef bool result_type;
|
||||
|
||||
enum cmp_result
|
||||
{
|
||||
Less = 0,
|
||||
Equal = 1,
|
||||
Greater = 2
|
||||
};
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Defines <=, >, >=, ==, !=, <=> in terms of <
|
||||
/// Default implementation of TLess is etl::less
|
||||
//***************************************************************************
|
||||
template <typename T, typename TLess = etl::less<T> >
|
||||
struct compare : public compare_types
|
||||
struct compare
|
||||
{
|
||||
enum cmp_result
|
||||
{
|
||||
Less = -1,
|
||||
Equal = 0,
|
||||
Greater = 1
|
||||
};
|
||||
|
||||
typedef typename etl::parameter_type<T>::type first_argument_type;
|
||||
typedef typename etl::parameter_type<T>::type second_argument_type;
|
||||
|
||||
static ETL_CONSTEXPR result_type lt(first_argument_type lhs, second_argument_type rhs)
|
||||
static ETL_CONSTEXPR bool lt(first_argument_type lhs, second_argument_type rhs)
|
||||
{
|
||||
return TLess()(lhs, rhs);
|
||||
}
|
||||
|
||||
static ETL_CONSTEXPR result_type gt(first_argument_type lhs, second_argument_type rhs)
|
||||
static ETL_CONSTEXPR bool gt(first_argument_type lhs, second_argument_type rhs)
|
||||
{
|
||||
return TLess()(rhs, lhs);
|
||||
}
|
||||
|
||||
static ETL_CONSTEXPR result_type lte(first_argument_type lhs, second_argument_type rhs)
|
||||
static ETL_CONSTEXPR bool lte(first_argument_type lhs, second_argument_type rhs)
|
||||
{
|
||||
return !gt(lhs, rhs);
|
||||
}
|
||||
|
||||
static ETL_CONSTEXPR result_type gte(first_argument_type lhs, second_argument_type rhs)
|
||||
static ETL_CONSTEXPR bool gte(first_argument_type lhs, second_argument_type rhs)
|
||||
{
|
||||
return !lt(lhs, rhs);
|
||||
}
|
||||
|
||||
static ETL_CONSTEXPR result_type eq(first_argument_type lhs, second_argument_type rhs)
|
||||
static ETL_CONSTEXPR bool eq(first_argument_type lhs, second_argument_type rhs)
|
||||
{
|
||||
return gte(lhs, rhs) && lte(lhs, rhs);
|
||||
}
|
||||
|
||||
static ETL_CONSTEXPR result_type ne(first_argument_type lhs, second_argument_type rhs)
|
||||
static ETL_CONSTEXPR bool ne(first_argument_type lhs, second_argument_type rhs)
|
||||
{
|
||||
return !eq(lhs, rhs);
|
||||
}
|
||||
|
||||
static ETL_CONSTEXPR cmp_result cmp(first_argument_type lhs, second_argument_type rhs)
|
||||
{
|
||||
return lt(lhs, rhs) ? Less : gt(lhs, rhs) ? Greater : Equal;
|
||||
return lt(lhs, rhs) ? cmp_result::Less : gt(lhs, rhs) ? cmp_result::Greater : cmp_result::Equal;
|
||||
}
|
||||
};
|
||||
|
||||
@ -106,18 +101,7 @@ namespace etl
|
||||
template <typename T, typename TLess = etl::less<T>>
|
||||
ETL_CONSTEXPR14 int three_way_compare(const T& lhs, const T& rhs)
|
||||
{
|
||||
if (lhs < rhs)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (lhs > rhs)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return etl::compare<T>::cmp(lhs, rhs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user