From 992348b4bb2d0de2bdc5fa3d35ee83625caff69a Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Thu, 19 Feb 2026 14:18:12 +0100 Subject: [PATCH] Add constexpr to array comparison operators (#1303) * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Add constexpr to array comparison operators --------- Co-authored-by: John Wellbelove Co-authored-by: Sergei --- include/etl/array.h | 4 ++-- test/test_array.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/etl/array.h b/include/etl/array.h index efb2ce04..f1624209 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -1136,7 +1136,7 @@ namespace etl ///\return true if the arrays are equal, otherwise false //************************************************************************* template - bool operator ==(const etl::array& lhs, const etl::array& rhs) + ETL_CONSTEXPR14 bool operator ==(const etl::array& lhs, const etl::array& rhs) { return etl::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin()); } @@ -1148,7 +1148,7 @@ namespace etl ///\return true if the arrays are not equal, otherwise false //************************************************************************* template - bool operator !=(const etl::array& lhs, const etl::array& rhs) + ETL_CONSTEXPR14 bool operator !=(const etl::array& lhs, const etl::array& rhs) { return !(lhs == rhs); } diff --git a/test/test_array.cpp b/test/test_array.cpp index 9edd0719..27eaf674 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -631,6 +631,16 @@ namespace CHECK(data1 == data2); } + //************************************************************************* + TEST(test_equal_constexpr) + { + ETL_CONSTEXPR14 Data data1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + ETL_CONSTEXPR14 Data data2 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + ETL_CONSTEXPR14 bool result = (data1 == data2); + CHECK(result); + } + //************************************************************************* TEST(test_not_equal) { @@ -640,6 +650,16 @@ namespace CHECK(data1 != data2); } + //************************************************************************* + TEST(test_not_equal_constexpr) + { + ETL_CONSTEXPR14 Data data1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + ETL_CONSTEXPR14 Data data2 = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; + + ETL_CONSTEXPR14 bool result = (data1 != data2); + CHECK(result); + } + //************************************************************************* TEST(test_less_than) {