Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Public Types | Public Member Functions
ext::iterator_range< Iterator > Class Template Reference

Implementation of iterator_range, i.e. pair of iterators. The class provides most notably begin and end methods to allow the class be used in foreach context. More...

#include <range.hpp>

Public Types

typedef Iterator iterator
 Copy of provided iterator. More...
 
typedef Iterator const_iterator
 Copy of provided const_iterator. More...
 
typedef std::iterator_traits< Iterator >::value_type value_type
 Copy of value_type from the wrapped iterators. More...
 

Public Member Functions

 iterator_range ()=default
 Constructor of empty iterator_range. Both iterators are initialized to default (same) value. More...
 
constexpr iterator_range (Iterator begin, Iterator end)
 Constructor to make iterator_range from pair of iterators. More...
 
constexpr Iterator begin () const
 Accessor of the iterator to the begining. More...
 
constexpr Iterator end () const
 Accessor of the iterator to the end. More...
 
constexpr std::iterator_traits< Iterator >::reference front () const
 Getter of the first value in the iterator_range. More...
 
constexpr std::iterator_traits< Iterator >::reference back () const
 Getter of the last value in the iterator_range. More...
 
constexpr std::iterator_traits< Iterator >::reference operator[] (typename std::iterator_traits< Iterator >::difference_type index) const
 Array subscript operator implementation. More...
 
constexpr bool empty () const
 Test whether the iterator_range is empty. More...
 
constexpr size_t size () const
 Getter of the distance between begin and end iterators. More...
 
void pop_front ()
 Advances the begin iterator. More...
 
void pop_front (typename std::iterator_traits< Iterator >::difference_type n)
 Advances the begin iterator n times. More...
 
void pop_back ()
 Retracts the end iterator. More...
 
void pop_back (typename std::iterator_traits< Iterator >::difference_type n)
 Retracts the end iterator n times. More...
 
std::pair< iterator_range, iterator_rangesplit (typename std::iterator_traits< Iterator >::difference_type index) const
 Creates two sub ranges based on middle position. The element at the middle position is included in the second iterator_range. More...
 
iterator_range slice (typename std::iterator_traits< Iterator >::difference_type start, typename std::iterator_traits< Iterator >::difference_type stop) const
 Creates a subrange of the iterator_range representing interaval of values from start to stop. More...
 
iterator_range slice (typename std::iterator_traits< Iterator >::difference_type start) const
 Creates a subrange of the iterator_range representing interaval of values from start to the end of the iterator_range. More...
 

Detailed Description

template<typename Iterator>
class ext::iterator_range< Iterator >

Implementation of iterator_range, i.e. pair of iterators. The class provides most notably begin and end methods to allow the class be used in foreach context.

Template Parameters
Iteratorthe type of wrapped pair of iterators

Member Typedef Documentation

◆ const_iterator

template<typename Iterator >
typedef Iterator ext::iterator_range< Iterator >::const_iterator

Copy of provided const_iterator.

◆ iterator

template<typename Iterator >
typedef Iterator ext::iterator_range< Iterator >::iterator

Copy of provided iterator.

◆ value_type

template<typename Iterator >
typedef std::iterator_traits<Iterator>::value_type ext::iterator_range< Iterator >::value_type

Copy of value_type from the wrapped iterators.

Constructor & Destructor Documentation

◆ iterator_range() [1/2]

template<typename Iterator >
ext::iterator_range< Iterator >::iterator_range ( )
default

Constructor of empty iterator_range. Both iterators are initialized to default (same) value.

Here is the caller graph for this function:

◆ iterator_range() [2/2]

template<typename Iterator >
constexpr ext::iterator_range< Iterator >::iterator_range ( Iterator  begin,
Iterator  end 
)
inlineconstexpr

Constructor to make iterator_range from pair of iterators.

Parameters
beginthe begining of the wrapped iterator_range
endthe end of the wrapped iterator_range

Member Function Documentation

◆ back()

template<typename Iterator >
constexpr std::iterator_traits< Iterator >::reference ext::iterator_range< Iterator >::back ( ) const
inlineconstexpr

Getter of the last value in the iterator_range.

Returns
reference to the last value

◆ begin()

template<typename Iterator >
constexpr Iterator ext::iterator_range< Iterator >::begin ( ) const
inlineconstexpr

Accessor of the iterator to the begining.

Returns
the begin iterator

◆ empty()

template<typename Iterator >
constexpr bool ext::iterator_range< Iterator >::empty ( ) const
inlineconstexpr

Test whether the iterator_range is empty.

Returns
true of the two iterators representing iterator_range are equal.

◆ end()

template<typename Iterator >
constexpr Iterator ext::iterator_range< Iterator >::end ( ) const
inlineconstexpr

Accessor of the iterator to the end.

Returns
the end iterator

◆ front()

template<typename Iterator >
constexpr std::iterator_traits< Iterator >::reference ext::iterator_range< Iterator >::front ( ) const
inlineconstexpr

Getter of the first value in the iterator_range.

Returns
reference to the first value

◆ operator[]()

template<typename Iterator >
constexpr std::iterator_traits< Iterator >::reference ext::iterator_range< Iterator >::operator[] ( typename std::iterator_traits< Iterator >::difference_type  index) const
inlineconstexpr

Array subscript operator implementation.

Returns
reference to the value at given distance from the begining

◆ pop_back() [1/2]

template<typename Iterator >
void ext::iterator_range< Iterator >::pop_back ( )
inline

Retracts the end iterator.

◆ pop_back() [2/2]

template<typename Iterator >
void ext::iterator_range< Iterator >::pop_back ( typename std::iterator_traits< Iterator >::difference_type  n)
inline

Retracts the end iterator n times.

◆ pop_front() [1/2]

template<typename Iterator >
void ext::iterator_range< Iterator >::pop_front ( )
inline

Advances the begin iterator.

◆ pop_front() [2/2]

template<typename Iterator >
void ext::iterator_range< Iterator >::pop_front ( typename std::iterator_traits< Iterator >::difference_type  n)
inline

Advances the begin iterator n times.

◆ size()

template<typename Iterator >
constexpr size_t ext::iterator_range< Iterator >::size ( ) const
inlineconstexpr

Getter of the distance between begin and end iterators.

Returns
the distance between begin and end iterators

◆ slice() [1/2]

template<typename Iterator >
iterator_range ext::iterator_range< Iterator >::slice ( typename std::iterator_traits< Iterator >::difference_type  start) const
inline

Creates a subrange of the iterator_range representing interaval of values from start to the end of the iterator_range.

If the start is positive or zero, the actual cut position is calcuated relative to the begining of the iterator_range. If the start is negative, the actual cut position is calculated relative to the end of the iterator_range.

The call is equivalent to slice ( begin, 0 ).

Example iterator_range ( 0, 1, 2, 3, 4, 5 ).slice ( 1 ) produces iterator_range ( 1, 2, 3, 4, 5 ); Example iterator_range ( 0, 1, 2, 3, 4, 5 ).slice ( -4 ) produces iterator_range ( 2, 3, 4, 5 );

Parameters
startthe begin position of the resulting subrange
Returns
subrange of the iterator_range.
Here is the call graph for this function:

◆ slice() [2/2]

template<typename Iterator >
iterator_range ext::iterator_range< Iterator >::slice ( typename std::iterator_traits< Iterator >::difference_type  start,
typename std::iterator_traits< Iterator >::difference_type  stop 
) const
inline

Creates a subrange of the iterator_range representing interaval of values from start to stop.

If the start is positive or zero, the actual cut position is calcuated relative to the begining of the iterator_range. If the start is negative, the actual cut position is calculated relative to the end of the iterator_range.

If the end is positive, the actual cut position is calcuated relative to the begining of the iterator_range. If the start is negative or zero, the actual cut position is calculated relative to the end of the iterator_range.

Example iterator_range ( 0, 1, 2, 3, 4, 5 ).slice ( 1, 3 ) produces iterator_range ( 1, 2 ); Example iterator_range ( 0, 1, 2, 3, 4, 5 ).slice ( -4, -1 ) produces iterator_range ( 2, 3, 4 );

Parameters
startthe begin position of the resulting subrange
endthe end position of the resulting subrange
Returns
subrange of the iterator_range.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ split()

template<typename Iterator >
std::pair< iterator_range, iterator_range > ext::iterator_range< Iterator >::split ( typename std::iterator_traits< Iterator >::difference_type  index) const
inline

Creates two sub ranges based on middle position. The element at the middle position is included in the second iterator_range.

Parameters
indexthe place where to cut the iterator_range in two
Returns
two subranges
Here is the call graph for this function:

The documentation for this class was generated from the following file: