mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-15 08:26:04 +08:00
Fixed move_iterator::operator+= and operator-= return type
move_iterator::operator+= / operator-= returned by value, but RandomAccessIterator requirements (and std::move_iterator) expect these to return move_iterator&. Returning by value also added an unnecessary copy and could break generic code expecting reference semantics.
This commit is contained in:
parent
288587070c
commit
8b0d8888e6
@ -576,13 +576,13 @@ namespace etl
|
||||
return move_iterator(current - n);
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR14 move_iterator operator+=(difference_type n)
|
||||
ETL_CONSTEXPR14 move_iterator& operator+=(difference_type n)
|
||||
{
|
||||
current += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR14 move_iterator operator-=(difference_type n)
|
||||
ETL_CONSTEXPR14 move_iterator& operator-=(difference_type n)
|
||||
{
|
||||
current -= n;
|
||||
return *this;
|
||||
|
||||
@ -550,6 +550,28 @@ namespace
|
||||
CHECK_EQUAL(true, mitr->valid);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_move_iterator_compound_assignment_returns_reference)
|
||||
{
|
||||
int data[] = {10, 20, 30, 40, 50};
|
||||
|
||||
etl::move_iterator<int*> mitr(&data[0]);
|
||||
|
||||
// operator+= must return a reference to *this
|
||||
etl::move_iterator<int*>& ref_plus = (mitr += 2);
|
||||
CHECK_EQUAL(&mitr, &ref_plus);
|
||||
CHECK_EQUAL(30, *mitr);
|
||||
|
||||
// operator-= must return a reference to *this
|
||||
etl::move_iterator<int*>& ref_minus = (mitr -= 1);
|
||||
CHECK_EQUAL(&mitr, &ref_minus);
|
||||
CHECK_EQUAL(20, *mitr);
|
||||
|
||||
// Chaining should work
|
||||
(mitr += 1) += 1;
|
||||
CHECK_EQUAL(40, *mitr);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_move_iterator_subtraction)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user