From e631a0fd9b82654d7a652615fb12a8c9db945e46 Mon Sep 17 00:00:00 2001 From: David Hebbeker Date: Fri, 13 Oct 2023 21:48:46 +0200 Subject: [PATCH 1/2] Return raw pointer for `etl::multi_span::operator->()`. (#773) - using `operator*()` in case getting the current element is changed one day - using `&` to get the address Simply returning `p_value` may break in case the internal type of `p_value` would change. This way it is more robust to changes. --- include/etl/multi_span.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/multi_span.h b/include/etl/multi_span.h index c24e893a1..7f98865dc 100644 --- a/include/etl/multi_span.h +++ b/include/etl/multi_span.h @@ -134,7 +134,7 @@ namespace etl //************************************************************************* pointer operator ->() { - return *p_value; + return &operator*(); } //************************************************************************* @@ -142,7 +142,7 @@ namespace etl //************************************************************************* const_pointer operator ->() const { - return *p_value; + return &operator*(); } //************************************************************************* From 6ee6177e826120d26d1835ba685decb01056d9ad Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 13 Oct 2023 21:32:30 +0100 Subject: [PATCH 2/2] Added -> operator test --- test/test_multi_span.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index a327ff861..d59c8d758 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -33,6 +33,7 @@ SOFTWARE. #include #include +#include namespace { @@ -46,6 +47,14 @@ namespace int data7[1]; int data8[2]; + struct Data + { + int i; + }; + + Data struct_data1[] = {Data{1}, Data{2}, Data{3}}; + Data struct_data2[] = {Data{4}, Data{5}, Data{6}}; + SUITE(test_multi_span) { //************************************************************************* @@ -140,5 +149,30 @@ namespace std::copy(expected.begin(), expected.end(), ms_int.begin()); CHECK(std::equal(expected.begin(), expected.end(), ms_int.begin())); } + + //************************************************************************* + TEST(test_member_pointer_operator) + { + std::vector> span_list = + { + etl::span(struct_data1), + etl::span(struct_data2) + }; + + etl::multi_span ms_data(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + + etl::multi_span::iterator itr = ms_data.begin(); + CHECK_EQUAL(struct_data1[0].i, itr->i); + ++itr; + CHECK_EQUAL(struct_data1[1].i, itr->i); + ++itr; + CHECK_EQUAL(struct_data1[2].i, itr->i); + ++itr; + CHECK_EQUAL(struct_data2[0].i, itr->i); + ++itr; + CHECK_EQUAL(struct_data2[1].i, itr->i); + ++itr; + CHECK_EQUAL(struct_data2[2].i, itr->i); + } }; }