From 591996e21ac2bc8a64f6ad63cb4b37c74f8abaf8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 4 Aug 2023 11:57:49 +0100 Subject: [PATCH] Added C++20 four iterator std::equal variants --- include/etl/algorithm.h | 27 ++++++++++++++++++++++++--- test/test_span_dynamic_extent.cpp | 10 +++++----- test/test_span_fixed_extent.cpp | 5 +++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index cb287de1..a2b06182 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -560,6 +560,7 @@ namespace etl //*************************************************************************** // equal #if ETL_USING_STL && ETL_USING_CPP20 + // Three parameter template [[nodiscard]] constexpr @@ -568,6 +569,7 @@ namespace etl return std::equal(first1, last1, first2); } + // Three parameter + predicate template [[nodiscard]] constexpr @@ -575,8 +577,27 @@ namespace etl { return std::equal(first1, last1, first2, predicate); } + + // Four parameter + template + [[nodiscard]] + constexpr + bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2, TIterator2 last2) + { + return std::equal(first1, last1, first2, last2); + } + + // Four parameter + Predicate + template + [[nodiscard]] + constexpr + bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2, TIterator2 last2, TPredicate predicate) + { + return std::equal(first1, last1, first2, last2, predicate); + } + #else - // Not pointer types or not trivially copyable. + template ETL_NODISCARD ETL_CONSTEXPR14 @@ -639,8 +660,8 @@ namespace etl // Four parameter, Predicate template ETL_NODISCARD - ETL_CONSTEXPR14 - bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2, TIterator2 last2, TPredicate predicate) + ETL_CONSTEXPR14 + bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2, TIterator2 last2, TPredicate predicate) { while ((first1 != last1) && (first2 != last2)) { diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index 8e1a62c5..cf62fcf6 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -42,12 +42,12 @@ namespace { static const size_t SIZE = 10UL; - typedef etl::array EtlData; - typedef std::array StlData; - typedef std::vector StlVData; + using EtlData = etl::array; + using StlData = std::array; + using StlVData = std::vector; - typedef etl::span View; - typedef etl::span CView; + using View = etl::span; + using CView = etl::span; EtlData etldata = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; StlData stldata = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 26469511..a4307e69 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -47,6 +47,7 @@ namespace typedef std::vector StlVData; typedef etl::span View; + typedef etl::span SView; typedef etl::span CView; EtlData etldata = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -998,6 +999,7 @@ namespace etl::array data1{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; etl::array data2{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; etl::array data3{ 0, 1, 2, 3, 4, 4, 6, 7, 8, 9 }; + etl::array data4{ 0, 1, 2, 3, 4, 5, 6, 7, 8 }; View view1{ data1 }; View view2{ data1 }; @@ -1005,18 +1007,21 @@ namespace View view4{ data3 }; View view6; View view7; + SView view8{ data4 }; CHECK_TRUE(etl::equal(view1, view2)); CHECK_TRUE(etl::equal(view1, view3)); CHECK_FALSE(etl::equal(view1, view4)); CHECK_TRUE(etl::equal(view6, view6)); CHECK_TRUE(etl::equal(view6, view7)); + CHECK_FALSE(etl::equal(view1, view8)); CHECK_TRUE(view1 == view2); CHECK_FALSE(view1 == view3); CHECK_FALSE(view1 == view4); CHECK_TRUE(view6 == view6); CHECK_TRUE(view6 == view7); + CHECK_FALSE(view1 == view8); } //*************************************************************************