Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added const iterators to span #986

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -413,8 +447,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 @@ -544,6 +580,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 @@ -560,6 +604,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 @@ -576,6 +628,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 @@ -584,6 +644,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
Loading