mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-15 08:26:04 +08:00
Fix fixed_iterator::operator* return type
fixed_iterator::operator* returned value_type by value, so writes like *it = ... modified a temporary rather than the underlying location. This broke the iterator’s intended use (e.g., writing to a fixed register/memory location). Now returning iterator_traits<TIterator>::reference instead (const and non-const overloads).
This commit is contained in:
parent
01ed29f817
commit
288587070c
@ -108,7 +108,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Dereference operator.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::value_type operator*()
|
||||
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::reference operator*()
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
@ -116,7 +116,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Dereference operator.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR const typename etl::iterator_traits<TIterator>::value_type operator*() const
|
||||
ETL_CONSTEXPR typename etl::iterator_traits<TIterator>::reference operator*() const
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
|
||||
@ -229,6 +229,22 @@ namespace
|
||||
CHECK(fi1 != fi3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_dereference_write_through)
|
||||
{
|
||||
int value = 42;
|
||||
etl::fixed_iterator<int*> fi(&value);
|
||||
|
||||
// Writing through the dereferenced iterator should modify the underlying value.
|
||||
*fi = 99;
|
||||
CHECK_EQUAL(99, value);
|
||||
|
||||
// Increment does nothing, so writing again still targets the same location.
|
||||
++fi;
|
||||
*fi = 123;
|
||||
CHECK_EQUAL(123, value);
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP14
|
||||
//*************************************************************************
|
||||
TEST(test_fixed_iterator_constexpr_ctor)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user