Template Class IteratorAdapter

Class Documentation

template<typename Iterator, typename T, T (*get_value)(Iterator)>
class IteratorAdapter

IteratorAdapter wraps an Iterator but returns the type specified by T (using the function get_value) whenever the IteratorAdapter is dereferenced.

Public Types

using difference_type = std::ptrdiff_t

Type when taking the difference between two iterators.

using value_type = std::remove_const_t<T>

Type of elements pointed to by the iterator.

using pointer = value_type*

Type to represent a pointer to an element pointed by the iterator.

using reference = value_type&

Type to represent a reference to an element pointed by the iterator.

using iterator_category = std::random_access_iterator_tag

Category to which the iterator belongs.

Public Functions

inline explicit IteratorAdapter(Iterator it)

Explicit constructor from an Iterator.

Parameters

it – iterator to wrap

inline operator Iterator()

Implicit conversion to Iterator.

Returns

Wrapped iterator

inline bool operator==(const IteratorAdapter &rhs)

Equal operator.

Parameters

rhs – iterator to compare to

Returns

true if iterators are equal

inline bool operator!=(const IteratorAdapter &rhs)

Not equal operator.

Parameters

rhs – iterator to compare to

Returns

true if iterators are not equal

inline IteratorAdapter &operator++()

Prefix increment operator.

Returns

*this

inline IteratorAdapter operator++(int)

Postfix increment operator.

Returns

Iterator (by value)

inline IteratorAdapter operator+(int amount) const

Addition operator.

Parameters

amount – to add

Returns

Iterator (by value)

inline IteratorAdapter operator-(int amount) const

Subtraction operator.

Parameters

amount – to subtract

Returns

Iterator (by value)

inline IteratorAdapter &operator--()

Prefix decrement operator.

Returns

*this

inline IteratorAdapter operator--(int)

Postfix decrement operator.

Returns

Iterator (by value)

inline std::ptrdiff_t operator-(IteratorAdapter const &rhs) const

Difference operator.

Parameters

rhs – iterator to compare to

Returns

Difference between iterator and rhs (iterator - rhs)

inline IteratorAdapter &operator+=(int amount)

Addition assignment operator.

Parameters

amount – to add to iterator

Returns

Modified iterator (by reference)

inline IteratorAdapter &operator-=(int amount)

Subtraction assignment operator.

Parameters

amount – to subtract from iterator

Returns

Modified iterator (by reference)

inline bool operator<(IteratorAdapter const &rhs) const

Less than operator.

Parameters

rhs – iterator to compare to

Returns

true if iterator is less than rhs (iterator < rhs)

inline bool operator<=(IteratorAdapter const &rhs) const

Less than or equal to operator.

Parameters

rhs – iterator to compare to

Returns

true if iterator is less than or equal to rhs (iterator <= rhs)

inline bool operator>(IteratorAdapter const &rhs) const

Greater than operator.

Parameters

rhs – iterator to compare to

Returns

true if iterator is greater than rhs (iterator > rhs)

inline bool operator>=(IteratorAdapter const &rhs) const

Greater than or equal to operator.

Parameters

rhs – iterator to compare to

Returns

true if iterator is greater than or equal to rhs (iterator >= rhs)

inline auto operator[](int index) const
Parameters

index – of element from iterator

Returns

Type T from element at index (using get_value())

inline auto operator*() const
Returns

Type T from element pointed to (using get_value())

inline auto operator->() const
Returns

Address of type T from element pointed to (using get_value())