From 4bc8d007372056856534f087c7b2e46b06f3b7c4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 27 Mar 2024 21:01:05 +0000 Subject: [PATCH] Modified return types --- include/etl/compare.h | 48 +++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/include/etl/compare.h b/include/etl/compare.h index 7a6d589b..e143366c 100644 --- a/include/etl/compare.h +++ b/include/etl/compare.h @@ -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 > - struct compare : public compare_types + struct compare { + enum cmp_result + { + Less = -1, + Equal = 0, + Greater = 1 + }; + typedef typename etl::parameter_type::type first_argument_type; typedef typename etl::parameter_type::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 > 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::cmp(lhs, rhs); } }