Skip to content

Commit

Permalink
Added const iterators to span
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandreichweinbmw committed Dec 3, 2024
1 parent a88a48d commit 7084716
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
76 changes: 72 additions & 4 deletions include/etl/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ namespace etl
typedef T* pointer;
typedef const T* const_pointer;

typedef T* iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef T* iterator;
typedef const T* const_iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;

typedef etl::circular_iterator<pointer> circular_iterator;
typedef etl::circular_iterator<ETL_OR_STD::reverse_iterator<pointer> > reverse_circular_iterator;
Expand Down Expand Up @@ -185,6 +187,14 @@ namespace etl
return pbegin;
}

//*************************************************************************
/// Returns a const iterator to the beginning of the span.
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
{
return pbegin;
}

//*************************************************************************
/// Returns an iterator to the beginning of the span.
//*************************************************************************
Expand All @@ -201,6 +211,14 @@ namespace etl
return circular_iterator(begin(), end());
}

//*************************************************************************
/// Returns a const iterator to the end of the span.
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
{
return (pbegin + Extent);
}

//*************************************************************************
/// Returns an iterator to the end of the span.
//*************************************************************************
Expand All @@ -209,6 +227,14 @@ namespace etl
return (pbegin + Extent);
}

//*************************************************************************
// Returns a const reverse iterator to the reverse beginning of the span.
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
{
return const_reverse_iterator((pbegin + Extent));
}

//*************************************************************************
// Returns an reverse iterator to the reverse beginning of the span.
//*************************************************************************
Expand All @@ -225,6 +251,14 @@ namespace etl
return reverse_circular_iterator(rbegin(), rend());
}

//*************************************************************************
/// Returns a const reverse iterator to the end of the span.
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
{
return const_reverse_iterator(pbegin);
}

//*************************************************************************
/// Returns a reverse iterator to the end of the span.
//*************************************************************************
Expand Down Expand Up @@ -393,8 +427,10 @@ namespace etl
typedef T* pointer;
typedef const T* const_pointer;

typedef T* iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef T* iterator;
typedef const T* const_iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;

typedef etl::circular_iterator<pointer> circular_iterator;
typedef etl::circular_iterator<ETL_OR_STD::reverse_iterator<pointer> > reverse_circular_iterator;
Expand Down Expand Up @@ -524,6 +560,14 @@ namespace etl
return pbegin;
}

//*************************************************************************
/// Returns a const iterator to the beginning of the span.
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
{
return pbegin;
}

//*************************************************************************
/// Returns an iterator to the beginning of the span.
//*************************************************************************
Expand All @@ -540,6 +584,14 @@ namespace etl
return circular_iterator(begin(), end());
}

//*************************************************************************
/// Returns a const iterator to the end of the span.
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
{
return pend;
}

//*************************************************************************
/// Returns an iterator to the end of the span.
//*************************************************************************
Expand All @@ -556,6 +608,14 @@ namespace etl
return reverse_iterator(pend);
}

//*************************************************************************
// Returns a const reverse iterator to the reverse beginning of the span.
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
{
return const_reverse_iterator(pend);
}

//*************************************************************************
/// Returns a reverse circular iterator to the end of the span.
//*************************************************************************
Expand All @@ -564,6 +624,14 @@ namespace etl
return reverse_circular_iterator(rbegin(), rend());
}

//*************************************************************************
/// Returns a const reverse iterator to the end of the span.
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
{
return const_reverse_iterator(pbegin);
}

//*************************************************************************
/// Returns a reverse iterator to the end of the span.
//*************************************************************************
Expand Down
4 changes: 4 additions & 0 deletions test/test_span_dynamic_extent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,19 @@ namespace
View view(etldata.begin(), etldata.end());
CView cview(etldata.begin(), etldata.end());

CHECK_EQUAL(etldata.cbegin(), view.cbegin());
CHECK_EQUAL(etldata.begin(), view.begin());
CHECK_EQUAL(etldata.begin(), cview.begin());

CHECK_EQUAL(etldata.cend(), view.crbegin().base());
CHECK_EQUAL(etldata.end(), view.rbegin().base());
CHECK_EQUAL(etldata.end(), cview.rbegin().base());

CHECK_EQUAL(etldata.cend(), view.cend());
CHECK_EQUAL(etldata.end(), view.end());
CHECK_EQUAL(etldata.end(), cview.end());

CHECK_EQUAL(etldata.cbegin(), view.crend().base());
CHECK_EQUAL(etldata.begin(), view.rend().base());
CHECK_EQUAL(etldata.begin(), cview.rend().base());
}
Expand Down
4 changes: 4 additions & 0 deletions test/test_span_fixed_extent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,19 @@ namespace
View view(etldata.begin(), etldata.end());
CView cview(etldata.begin(), etldata.end());

CHECK_EQUAL(etldata.cbegin(), view.cbegin());
CHECK_EQUAL(etldata.begin(), view.begin());
CHECK_EQUAL(etldata.begin(), cview.begin());

CHECK_EQUAL(etldata.cend(), view.crbegin().base());
CHECK_EQUAL(etldata.end(), view.rbegin().base());
CHECK_EQUAL(etldata.end(), cview.rbegin().base());

CHECK_EQUAL(etldata.cend(), view.cend());
CHECK_EQUAL(etldata.end(), view.end());
CHECK_EQUAL(etldata.end(), cview.end());

CHECK_EQUAL(etldata.cbegin(), view.crend().base());
CHECK_EQUAL(etldata.begin(), view.rend().base());
CHECK_EQUAL(etldata.begin(), cview.rend().base());
}
Expand Down

0 comments on commit 7084716

Please sign in to comment.