Skip to content

Commit

Permalink
Merge branch 'pull-request/#773-Return-raw-pointer-for-etl-multi_span…
Browse files Browse the repository at this point in the history
…-operator' into development
  • Loading branch information
John Wellbelove committed Oct 13, 2023
2 parents 822e244 + 6ee6177 commit f616a24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/etl/multi_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ namespace etl
//*************************************************************************
pointer operator ->()
{
return *p_value;
return &operator*();
}

//*************************************************************************
/// -> operator
//*************************************************************************
const_pointer operator ->() const
{
return *p_value;
return &operator*();
}

//*************************************************************************
Expand Down
34 changes: 34 additions & 0 deletions test/test_multi_span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOFTWARE.

#include <iterator>
#include <vector>
#include <array>

namespace
{
Expand All @@ -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)
{
//*************************************************************************
Expand Down Expand Up @@ -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<etl::span<Data>> span_list =
{
etl::span<Data>(struct_data1),
etl::span<Data>(struct_data2)
};

etl::multi_span<Data> ms_data(etl::multi_span<Data>::span_list_type(std::begin(span_list), std::end(span_list)));

etl::multi_span<Data>::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);
}
};
}

0 comments on commit f616a24

Please sign in to comment.