MCKL
Monte Carlo Kernel Library
Public Types | Public Member Functions | Friends | List of all members
mckl::StepIterator< Base > Class Template Reference

Iterator adapter which increment the base iterator in multiple steps. More...

#include <mckl/core/iterator.hpp>

Public Types

using difference_type = std::make_signed_t< typename std::iterator_traits< Base >::difference_type >
 
using iterator_category = typename std::iterator_traits< Base >::iterator_category
 
using pointer = typename std::iterator_traits< Base >::pointer
 
using reference = typename std::iterator_traits< Base >::reference
 
using value_type = typename std::iterator_traits< Base >::value_type
 

Public Member Functions

 StepIterator () noexcept(std::is_nothrow_default_constructible< Base >::value)
 Default constructor. More...
 
 StepIterator (Base base, difference_type step=1) noexcept(std::is_nothrow_copy_constructible< Base >::value)
 Convert from a base iterator. More...
 
template<typename T >
 StepIterator (const StepIterator< T > &other) noexcept(std::is_nothrow_copy_constructible< Base >::value)
 Convert from compatible StepIterator. More...
 
Base base () const
 Return the underlying base iterator. More...
 
reference operator* () const
 Dereference the base iterator. More...
 
Base operator-> () const
 Member selection through the base iterator. More...
 
template<typename IntType >
reference operator[] (IntType n) const
 Equivalent to *((*this) + n) More...
 
difference_type step () const
 Return the increment step size. More...
 

Friends

bool operator!= (const StepIterator &iter1, const StepIterator &iter2)
 Compare inequality. More...
 
template<typename IntType >
StepIterator operator+ (const StepIterator &iter, IntType n)
 Addition with integer: advance the base iterator by a distance of n * iter.step() More...
 
template<typename IntType >
StepIterator operator+ (IntType n, const StepIterator &iter)
 Addition with integer. More...
 
StepIteratoroperator++ (StepIterator &iter)
 Prefix increment: advance the base iterator by a distance of iter.step() More...
 
StepIterator operator++ (StepIterator &iter, int)
 Postfix increment. More...
 
template<typename IntType >
StepIteratoroperator+= (StepIterator &iter, IntType n)
 Compound addition with integer. More...
 
template<typename IntType >
StepIterator operator- (const StepIterator &iter, IntType n)
 Subtraction with integer: advance the base iterator by a distance -n * iter.step() More...
 
difference_type operator- (const StepIterator &iter1, const StepIterator &iter2)
 Difference between two iterators. More...
 
StepIteratoroperator-- (StepIterator &iter)
 Prefix decrement: advance the base iterator by a distance of -iter.step() More...
 
StepIterator operator-- (StepIterator &iter, int)
 Postfix decrement. More...
 
template<typename IntType >
StepIteratoroperator-= (StepIterator &iter, IntType n)
 Compound subtraction with integer. More...
 
bool operator< (const StepIterator &iter1, const StepIterator &iter2)
 Compare less than relation. More...
 
bool operator<= (const StepIterator &iter1, const StepIterator &iter2)
 Compare less than relation or equality. More...
 
bool operator== (const StepIterator &iter1, const StepIterator &iter2)
 Compare equality. More...
 
bool operator> (const StepIterator &iter1, const StepIterator &iter2)
 Compare greater than relation. More...
 
bool operator>= (const StepIterator &iter1, const StepIterator &iter2)
 Compare greater than relation or equality. More...
 

Detailed Description

template<typename Base>
class mckl::StepIterator< Base >

Iterator adapter which increment the base iterator in multiple steps.

Template Parameters
BaseAn iterator type

Definition at line 44 of file iterator.hpp.

Member Typedef Documentation

◆ difference_type

template<typename Base>
using mckl::StepIterator< Base >::difference_type = std::make_signed_t< typename std::iterator_traits<Base>::difference_type>

Definition at line 48 of file iterator.hpp.

◆ iterator_category

template<typename Base>
using mckl::StepIterator< Base >::iterator_category = typename std::iterator_traits<Base>::iterator_category

Definition at line 53 of file iterator.hpp.

◆ pointer

template<typename Base>
using mckl::StepIterator< Base >::pointer = typename std::iterator_traits<Base>::pointer

Definition at line 50 of file iterator.hpp.

◆ reference

template<typename Base>
using mckl::StepIterator< Base >::reference = typename std::iterator_traits<Base>::reference

Definition at line 51 of file iterator.hpp.

◆ value_type

template<typename Base>
using mckl::StepIterator< Base >::value_type = typename std::iterator_traits<Base>::value_type

Definition at line 49 of file iterator.hpp.

Constructor & Destructor Documentation

◆ StepIterator() [1/3]

template<typename Base>
mckl::StepIterator< Base >::StepIterator ( )
inlinenoexcept

Default constructor.

Definition at line 56 of file iterator.hpp.

◆ StepIterator() [2/3]

template<typename Base>
mckl::StepIterator< Base >::StepIterator ( Base  base,
difference_type  step = 1 
)
inlineexplicitnoexcept

Convert from a base iterator.

Parameters
baseThe base iterator
stepThe step size. Each call of the increment/decrement operator of the newly constructed iterator will advance it by a distance equal to step.
Precondition
Base is copy constructible

Definition at line 69 of file iterator.hpp.

◆ StepIterator() [3/3]

template<typename Base>
template<typename T >
mckl::StepIterator< Base >::StepIterator ( const StepIterator< T > &  other)
inlinenoexcept

Convert from compatible StepIterator.

Precondition
T is convertible to Base

Definition at line 79 of file iterator.hpp.

Member Function Documentation

◆ base()

template<typename Base>
Base mckl::StepIterator< Base >::base ( ) const
inline

Return the underlying base iterator.

Definition at line 86 of file iterator.hpp.

◆ operator*()

template<typename Base>
reference mckl::StepIterator< Base >::operator* ( ) const
inline

Dereference the base iterator.

Definition at line 92 of file iterator.hpp.

◆ operator->()

template<typename Base>
Base mckl::StepIterator< Base >::operator-> ( ) const
inline

Member selection through the base iterator.

Definition at line 95 of file iterator.hpp.

◆ operator[]()

template<typename Base>
template<typename IntType >
reference mckl::StepIterator< Base >::operator[] ( IntType  n) const
inline

Equivalent to *((*this) + n)

Precondition
Base is an input iterator
Base is a bidirectional iterator if n * step() < 0

Definition at line 102 of file iterator.hpp.

◆ step()

template<typename Base>
difference_type mckl::StepIterator< Base >::step ( ) const
inline

Return the increment step size.

Definition at line 89 of file iterator.hpp.

Friends And Related Function Documentation

◆ operator!=

template<typename Base>
bool operator!= ( const StepIterator< Base > &  iter1,
const StepIterator< Base > &  iter2 
)
friend

Compare inequality.

Precondition
Base is inequality comparable
iter1.step() == iter2.step()

Definition at line 124 of file iterator.hpp.

◆ operator+ [1/2]

template<typename Base>
template<typename IntType >
StepIterator operator+ ( const StepIterator< Base > &  iter,
IntType  n 
)
friend

Addition with integer: advance the base iterator by a distance of n * iter.step()

Precondition
Base is an input iterator
Base is a bidirectional iterator if n * iter.step() < 0

Definition at line 241 of file iterator.hpp.

◆ operator+ [2/2]

template<typename Base>
template<typename IntType >
StepIterator operator+ ( IntType  n,
const StepIterator< Base > &  iter 
)
friend

Addition with integer.

Precondition
Base is an input iterator
Base is a bidirectional iterator if n * iter.step() < 0

Definition at line 256 of file iterator.hpp.

◆ operator++ [1/2]

template<typename Base>
StepIterator& operator++ ( StepIterator< Base > &  iter)
friend

Prefix increment: advance the base iterator by a distance of iter.step()

Precondition
Base is an input iterator
Base is a bidirectional iterator if iter.step() < 0

Definition at line 188 of file iterator.hpp.

◆ operator++ [2/2]

template<typename Base>
StepIterator operator++ ( StepIterator< Base > &  iter,
int   
)
friend

Postfix increment.

Precondition
Base is an input iterator
Base is a bidirectional iterator if iter.step() < 0

Definition at line 201 of file iterator.hpp.

◆ operator+=

template<typename Base>
template<typename IntType >
StepIterator& operator+= ( StepIterator< Base > &  iter,
IntType  n 
)
friend

Compound addition with integer.

Precondition
Base is an input iterator
Base is a bidirectional iterator if n * iter.step() < 0

Definition at line 277 of file iterator.hpp.

◆ operator- [1/2]

template<typename Base>
template<typename IntType >
StepIterator operator- ( const StepIterator< Base > &  iter,
IntType  n 
)
friend

Subtraction with integer: advance the base iterator by a distance -n * iter.step()

Precondition
Base is an input iterator
Base is a bidirectional iterator if n * iter.step() > 0

Definition at line 267 of file iterator.hpp.

◆ operator- [2/2]

template<typename Base>
difference_type operator- ( const StepIterator< Base > &  iter1,
const StepIterator< Base > &  iter2 
)
friend

Difference between two iterators.

Precondition
Base is an input iterator
iter1 is reachable by incrementing iter2
iter1.step() == iter2.step()

Definition at line 297 of file iterator.hpp.

◆ operator-- [1/2]

template<typename Base>
StepIterator& operator-- ( StepIterator< Base > &  iter)
friend

Prefix decrement: advance the base iterator by a distance of -iter.step()

Precondition
Base is a input iterator
Base is a bidirectional iterator if iter.step() > 0

Definition at line 214 of file iterator.hpp.

◆ operator-- [2/2]

template<typename Base>
StepIterator operator-- ( StepIterator< Base > &  iter,
int   
)
friend

Postfix decrement.

Precondition
Base is a input iterator
Base is a bidirectional iterator if iter.step() > 0

Definition at line 227 of file iterator.hpp.

◆ operator-=

template<typename Base>
template<typename IntType >
StepIterator& operator-= ( StepIterator< Base > &  iter,
IntType  n 
)
friend

Compound subtraction with integer.

Precondition
Base is an input iterator
Base is a bidirectional iterator if n * iter.step() > 0

Definition at line 287 of file iterator.hpp.

◆ operator<

template<typename Base>
bool operator< ( const StepIterator< Base > &  iter1,
const StepIterator< Base > &  iter2 
)
friend

Compare less than relation.

Precondition
Base is less than comparable
iter1.step() == iter2.step()

Definition at line 137 of file iterator.hpp.

◆ operator<=

template<typename Base>
bool operator<= ( const StepIterator< Base > &  iter1,
const StepIterator< Base > &  iter2 
)
friend

Compare less than relation or equality.

Precondition
Base is less than or equality comparable
iter1.step() == iter2.step()

Definition at line 149 of file iterator.hpp.

◆ operator==

template<typename Base>
bool operator== ( const StepIterator< Base > &  iter1,
const StepIterator< Base > &  iter2 
)
friend

Compare equality.

Precondition
Base is equality comparable
iter1.step() == iter2.step()

Definition at line 111 of file iterator.hpp.

◆ operator>

template<typename Base>
bool operator> ( const StepIterator< Base > &  iter1,
const StepIterator< Base > &  iter2 
)
friend

Compare greater than relation.

Precondition
Base is greater than comparable
iter1.step() == iter2.step()

Definition at line 162 of file iterator.hpp.

◆ operator>=

template<typename Base>
bool operator>= ( const StepIterator< Base > &  iter1,
const StepIterator< Base > &  iter2 
)
friend

Compare greater than relation or equality.

Precondition
Base is greater than or equality comparable
iter1.step() == iter2.step()

Definition at line 174 of file iterator.hpp.