LiteFX 0.4.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
LiteFX::CovariantIterator< T > Struct Template Reference

Wraps an iterator and returns covariants of type T of the iterated value. More...

#include <containers.hpp>

Public Types

using value_type = std::remove_cvref_t<T>
 The type of the value that is iterated.
 
using iterator_category = std::forward_iterator_tag
 The category of the iterator.
 
using difference_type = std::ptrdiff_t
 The type that expresses the difference between two iterators.
 
using pointer = std::remove_reference_t<T>*
 The type of a pointer returned by the iterator.
 

Public Member Functions

 CovariantIterator ()
 Initializes a new iterator instance. Always throws a RuntimeException.
 
template<typename TIterator >
 CovariantIterator (const TIterator &it)
 Initializes a new iterator instance.
 
 CovariantIterator (const CovariantIterator &_other)
 Copies another iterator instance.
 
 CovariantIterator (CovariantIterator &&_other) noexcept=default
 Takes ownership over another iterator instances.
 
CovariantIteratoroperator= (const CovariantIterator &_other)
 Copies another iterator instance.
 
CovariantIteratoroperator= (CovariantIterator &&_other)=default
 Takes ownership over another iterator instances.
 
 ~CovariantIterator () noexcept=default
 Releases the iterator.
 
operator* () const
 Returns a reference of the value at the current iterator position.
 
pointer operator-> ()
 Returns a pointer to the value at the current iterator position.
 
CovariantIteratoroperator++ ()
 Increments the iterator position by one.
 
CovariantIterator operator++ (int)
 Increments the iterator position by one and returns the previous iterator.
 
bool operator== (const CovariantIterator &_other) const
 Checks if two iterators are equal, i.e. they are pointing to the same value.
 

Detailed Description

template<typename T>
struct LiteFX::CovariantIterator< T >

Wraps an iterator and returns covariants of type T of the iterated value.

This iterator uses type erasure to hide the actual iterated types from the interface. This allows to iterate a range of class instances as a range of base class instances. However, due to the type erasure, each iteration requires a virtual indirection, resulting in slightly lower performance. Limit the use of this iterator to base class interfaces and return a reference to the actual underlying range in child classes instead for most performance.

Template Parameters
TThe type returned by the iterator, that is covariant to the actual iterated type.
See also
Enumerable

Member Typedef Documentation

◆ difference_type

template<typename T >
using LiteFX::CovariantIterator< T >::difference_type = std::ptrdiff_t

The type that expresses the difference between two iterators.

◆ iterator_category

template<typename T >
using LiteFX::CovariantIterator< T >::iterator_category = std::forward_iterator_tag

The category of the iterator.

◆ pointer

template<typename T >
using LiteFX::CovariantIterator< T >::pointer = std::remove_reference_t<T>*

The type of a pointer returned by the iterator.

◆ value_type

template<typename T >
using LiteFX::CovariantIterator< T >::value_type = std::remove_cvref_t<T>

The type of the value that is iterated.

Constructor & Destructor Documentation

◆ CovariantIterator() [1/4]

template<typename T >
LiteFX::CovariantIterator< T >::CovariantIterator ( )
inlineexplicit

Initializes a new iterator instance. Always throws a RuntimeException.

This constructor is only defined to satisfy the std::ranges::range constraint for ranges that return this iterator. Attempting to default-initialize a CovariantInterator will result in a runtime error.

◆ CovariantIterator() [2/4]

template<typename T >
template<typename TIterator >
LiteFX::CovariantIterator< T >::CovariantIterator ( const TIterator & it)
inline

Initializes a new iterator instance.

Template Parameters
TIteratorThe type of the iterator that returns the value instances.
Parameters
itThe iterator to wrap within the iterator instance.

◆ CovariantIterator() [3/4]

template<typename T >
LiteFX::CovariantIterator< T >::CovariantIterator ( const CovariantIterator< T > & _other)
inline

Copies another iterator instance.

Parameters
_otherThe iterator to copy.

◆ CovariantIterator() [4/4]

template<typename T >
LiteFX::CovariantIterator< T >::CovariantIterator ( CovariantIterator< T > && _other)
inlinedefaultnoexcept

Takes ownership over another iterator instances.

Parameters
_otherThe iterator instance to take over.

◆ ~CovariantIterator()

template<typename T >
LiteFX::CovariantIterator< T >::~CovariantIterator ( )
defaultnoexcept

Releases the iterator.

Member Function Documentation

◆ operator*()

template<typename T >
T LiteFX::CovariantIterator< T >::operator* ( ) const
inline

Returns a reference of the value at the current iterator position.

Returns
A reference of the value at the current iterator position.

◆ operator++() [1/2]

template<typename T >
CovariantIterator & LiteFX::CovariantIterator< T >::operator++ ( )
inline

Increments the iterator position by one.

Returns
A reference of the current iterator.

◆ operator++() [2/2]

template<typename T >
CovariantIterator LiteFX::CovariantIterator< T >::operator++ ( int )
inline

Increments the iterator position by one and returns the previous iterator.

Returns
A copy of the previous iterator.

◆ operator->()

template<typename T >
pointer LiteFX::CovariantIterator< T >::operator-> ( )
inline

Returns a pointer to the value at the current iterator position.

This operator is only available, if the iterated type is a lvalue reference.

Returns
A pointer to the value at the current iterator position.

◆ operator=() [1/2]

template<typename T >
CovariantIterator & LiteFX::CovariantIterator< T >::operator= ( const CovariantIterator< T > & _other)
inline

Copies another iterator instance.

Parameters
_other
Returns

◆ operator=() [2/2]

template<typename T >
CovariantIterator & LiteFX::CovariantIterator< T >::operator= ( CovariantIterator< T > && _other)
inlinedefault

Takes ownership over another iterator instances.

Parameters
_otherThe iterator instance to take over.
Returns
A reference to the current iterator instance.

◆ operator==()

template<typename T >
bool LiteFX::CovariantIterator< T >::operator== ( const CovariantIterator< T > & _other) const
inline

Checks if two iterators are equal, i.e. they are pointing to the same value.

Parameters
_otherThe iterator to check against.
Returns
true, if the iterators are pointing to the same value.