31#ifndef ETL_CIRCULAR_ITERATOR_INCLUDED
32#define ETL_CIRCULAR_ITERATOR_INCLUDED
36#include "static_assert.h"
42 namespace private_circular_iterator
47 template <
typename TIterator>
49 :
public etl::iterator<typename etl::iterator_traits<TIterator>::iterator_category, typename etl::iterator_traits<TIterator>::value_type>
53 typedef typename etl::iterator_traits<TIterator>::value_type value_type;
54 typedef typename etl::iterator_traits<TIterator>::difference_type difference_type;
55 typedef typename etl::iterator_traits<TIterator>::pointer pointer;
56 typedef typename etl::iterator_traits<TIterator>::reference reference;
57 typedef typename etl::iterator_traits<TIterator>::iterator_category iterator_category;
104 ETL_CONSTEXPR14 TIterator
begin()
const
112 ETL_CONSTEXPR14 TIterator
end()
const
120 ETL_CONSTEXPR14
size_t size()
const
168 ETL_CONSTEXPR14
operator TIterator()
const
193 template <typename TIterator, typename TTag = typename etl::iterator_traits<TIterator>::iterator_category>
196 ETL_STATIC_ASSERT((etl::is_same<TTag, ETL_OR_STD::input_iterator_tag>::value_type),
"input_iterator_catagory is not supported by circular_iterator");
197 ETL_STATIC_ASSERT((etl::is_same<TTag, ETL_OR_STD::output_iterator_tag>::value_type),
"output_iterator_catagory is not supported by circular_iterator");
205 template <
typename TIterator>
215 using common_t::operator=;
217 typedef typename common_t::value_type value_type;
218 typedef typename common_t::difference_type difference_type;
219 typedef typename common_t::pointer pointer;
220 typedef typename common_t::reference reference;
221 typedef typename common_t::iterator_category iterator_category;
235 :
common_t(itr_begin_, itr_end_, itr_begin_)
243 :
common_t(itr_begin_, itr_end_, start_)
260 common_t::operator=(other);
270 if (++this->itr == this->itr_end)
272 this->itr = this->itr_begin;
296 template <
typename TIterator>
306 using common_t::operator=;
308 typedef typename common_t::value_type value_type;
309 typedef typename common_t::difference_type difference_type;
310 typedef typename common_t::pointer pointer;
311 typedef typename common_t::reference reference;
312 typedef typename common_t::iterator_category iterator_category;
326 :
common_t(itr_begin_, itr_end_, itr_begin_)
334 :
common_t(itr_begin_, itr_end_, start_)
351 common_t::operator=(other);
361 if (++this->itr == this->itr_end)
363 this->itr = this->itr_begin;
386 if (this->itr == this->itr_begin)
390 this->itr = ritr.base();
418 template <
typename TIterator>
428 using common_t::operator=;
430 typedef typename common_t::value_type value_type;
431 typedef typename common_t::difference_type difference_type;
432 typedef typename common_t::pointer pointer;
433 typedef typename common_t::reference reference;
434 typedef typename common_t::iterator_category iterator_category;
448 :
common_t(itr_begin_, itr_end_, itr_begin_)
456 :
common_t(itr_begin_, itr_end_, start_)
473 common_t::operator=(other);
483 if (++this->itr == this->itr_end)
485 this->itr = this->itr_begin;
508 if (this->itr == this->itr_begin)
512 this->itr = ritr.base();
539 const difference_type length = difference_type(this->size());
544 const difference_type distance_from_begin = etl::distance(this->itr_begin, this->itr);
545 const difference_type distance_to_end = etl::distance(this->itr, this->itr_end);
549 if (distance_to_end > offset)
551 offset = distance_from_begin + offset;
555 offset = offset - distance_to_end;
562 if (distance_from_begin >= offset)
564 offset = distance_from_begin - offset;
568 offset = offset - distance_from_begin;
569 offset = length - offset;
573 this->itr = this->itr_begin + offset;
584 return operator +=(-offset);
594 template <
typename TIterator>
604 using impl_t::operator=;
606 typedef typename impl_t::value_type value_type;
607 typedef typename impl_t::difference_type difference_type;
608 typedef typename impl_t::pointer pointer;
609 typedef typename impl_t::reference reference;
610 typedef typename impl_t::iterator_category iterator_category;
615 ETL_CONSTEXPR14 circular_iterator()
623 ETL_CONSTEXPR14 circular_iterator(TIterator itr_begin_, TIterator itr_end_)
624 :
impl_t(itr_begin_, itr_end_, itr_begin_)
631 ETL_CONSTEXPR14 circular_iterator(TIterator itr_begin_, TIterator itr_end_, TIterator start_)
632 :
impl_t(itr_begin_, itr_end_, start_)
639 ETL_CONSTEXPR14 circular_iterator(
const circular_iterator& other)
647 ETL_CONSTEXPR14 circular_iterator& operator =(
const circular_iterator& other)
649 impl_t::operator=(other);
658 template <
typename TIterator>
659 ETL_CONSTEXPR14 etl::circular_iterator<TIterator>
operator +(etl::circular_iterator<TIterator>& lhs,
660 typename etl::iterator_traits<TIterator>::difference_type offset)
662 etl::circular_iterator<TIterator> result(lhs);
671 template <
typename TIterator>
672 ETL_CONSTEXPR14 etl::circular_iterator<TIterator>
operator -(etl::circular_iterator<TIterator>& lhs,
673 typename etl::iterator_traits<TIterator>::difference_type offset)
675 etl::circular_iterator<TIterator> result(lhs);
684 template <
typename TIterator>
685 ETL_CONSTEXPR14
typename etl::iterator_traits<TIterator>::difference_type
operator -(etl::circular_iterator<TIterator>& lhs,
686 etl::circular_iterator<TIterator>& rhs)
688 return TIterator(lhs) - TIterator(rhs);
694 template <
typename TIterator>
695 ETL_CONSTEXPR14
bool operator ==(
const etl::circular_iterator<TIterator>& lhs,
696 const etl::circular_iterator<TIterator>& rhs)
698 return TIterator(lhs) == TIterator(rhs);
704 template <
typename TIterator>
705 ETL_CONSTEXPR14
bool operator ==(
const etl::circular_iterator<TIterator>& lhs,
708 return TIterator(lhs) == rhs;
714 template <
typename TIterator>
716 const etl::circular_iterator<TIterator>& rhs)
718 return lhs == TIterator(rhs);
725 template <
typename TIterator>
726 ETL_CONSTEXPR14
bool operator !=(
const etl::circular_iterator<TIterator>& lhs,
727 const etl::circular_iterator<TIterator>& rhs)
729 return !(lhs == rhs);
735 template <
typename TIterator>
736 ETL_CONSTEXPR14
bool operator !=(
const etl::circular_iterator<TIterator>& lhs,
739 return !(lhs == rhs);
745 template <
typename TIterator>
747 const etl::circular_iterator<TIterator>& rhs)
749 return !(lhs == rhs);
Common circular iterator implementation.
Definition: circular_iterator.h:50
ETL_CONSTEXPR14 TIterator current() const
Conversion to base iterator type.
Definition: circular_iterator.h:176
ETL_CONSTEXPR14 value_type operator*()
Dereference operator.
Definition: circular_iterator.h:136
TIterator itr_end
The underlying end iterator.
Definition: circular_iterator.h:184
ETL_CONSTEXPR14 bool empty() const
Is there nothing to iterate over?
Definition: circular_iterator.h:128
ETL_CONSTEXPR14 TIterator operator->()
-> operator.
Definition: circular_iterator.h:152
ETL_CONSTEXPR14 circular_iterator_common()
Default constructor.
Definition: circular_iterator.h:62
ETL_CONSTEXPR14 TIterator begin() const
Beginning of the range.
Definition: circular_iterator.h:104
TIterator itr_begin
The underlying begin iterator.
Definition: circular_iterator.h:183
ETL_CONSTEXPR14 TIterator end() const
End of the range.
Definition: circular_iterator.h:112
ETL_CONSTEXPR14 size_t size() const
How long is the range?
Definition: circular_iterator.h:120
TIterator itr
The underlying iterator.
Definition: circular_iterator.h:185
ETL_CONSTEXPR14 circular_iterator_common & operator=(const circular_iterator_common &other)
Assignment.
Definition: circular_iterator.h:92
Definition: iterator.h:228
Definition: circular_iterator.h:597
Definition: circular_iterator.h:195
bitset_ext
Definition: absolute.h:38
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator-(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition: circular_iterator.h:672
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:645
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:633
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator+(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition: circular_iterator.h:659
Definition: iterator.h:53
Definition: iterator.h:52
iterator
Definition: iterator.h:399
Definition: iterator.h:54