CXXIter 0.2
Loading...
Searching...
No Matches
CXXIter::trait::Source< TContainer > Struct Template Reference

SourceTrait, that is used by CXXIter's standard source classes CXXIter::SrcMov, CXXIter::SrcRef and CXXIter::SrcCRef. More...

#include <Traits.h>

Collaboration diagram for CXXIter::trait::Source< TContainer >:

Classes

struct  ConstIteratorState
 Type of the state structure stored in CXXIter's source classes, used to keep track of the iteration progress. More...
 
struct  IteratorState
 Type of the state structure stored in CXXIter's source classes, used to keep track of the iteration progress. More...
 

Public Types

using Item = typename TContainer::value_type
 Type of the item TContainer holds and provides for the iterator. More...
 
using ItemRef = typename TContainer::reference
 Type of the item TContainer holds and provides for the iterator, in referenced form. More...
 
using ItemConstRef = typename TContainer::const_reference
 Type of the item TContainer holds and provides for the iterator, in const referenced form. More...
 

Static Public Member Functions

static constexpr SizeHint sizeHint (const TContainer &container)
 Report a size hint for a source on the given container. More...
 
static constexpr IteratorState initIterator (TContainer &container)
 Return an initial IteratorState instance for iteration on the given container. More...
 
static constexpr ConstIteratorState initIterator (const TContainer &container)
 Return an initial IteratorState instance for iteration on the given container. More...
 
static constexpr bool hasNext (TContainer &container, IteratorState &iter)
 Checks whether there is a next item in the iteration with the given iter state on the given container. More...
 
static constexpr bool hasNext (const TContainer &container, ConstIteratorState &iter)
 Checks whether there is a next item in the iteration with the given iter state on the given container. More...
 
static constexpr ItemRef next (TContainer &container, IteratorState &iter)
 Return the next item in the iteration with the given iter state on the given container. More...
 
static constexpr ItemConstRef next (const TContainer &container, ConstIteratorState &iter)
 Return the next item in the iteration with the given iter state on the given container. More...
 
static constexpr ItemRef peekNext (TContainer &container, IteratorState &iter)
 Return the next item in the iteration with the given iter state on the given container, without advancing. More...
 
static constexpr ItemConstRef peekNext (const TContainer &container, ConstIteratorState &iter)
 Return the next item in the iteration with the given iter state on the given container, without advancing. More...
 
static constexpr size_t skipN (const TContainer &container, IteratorState &iter, size_t n)
 Skip the next n elements from the container. More...
 
static constexpr size_t skipN (const TContainer &container, ConstIteratorState &iter, size_t n)
 Skip the next n elements from the container. More...
 
Double-Ended iterator functionality (optional)
static constexpr ItemRef nextBack (TContainer &container, IteratorState &iter)
 Return the next item from the back of the iteration with the given iter state on the given container. More...
 
static constexpr ItemConstRef nextBack (const TContainer &container, ConstIteratorState &iter)
 Return the next item from the back of the iteration with the given iter state on the given container. More...
 
static constexpr size_t skipNBack (const TContainer &container, IteratorState &iter, size_t n)
 Skip the next n elements from the back of this iterator. More...
 
static constexpr size_t skipNBack (const TContainer &container, ConstIteratorState &iter, size_t n)
 Skip the next n elements from the back of this iterator. More...
 

Detailed Description

template<typename TContainer>
struct CXXIter::trait::Source< TContainer >

SourceTrait, that is used by CXXIter's standard source classes CXXIter::SrcMov, CXXIter::SrcRef and CXXIter::SrcCRef.

If you want to add support for your own containers to these sources, and thus to CXXIter::from() calls, create a template specialization of CXXIter::SourceTrait, for your container class.

This is the default implementation supporting all STL containers.

Definition at line 121 of file Traits.h.

Member Typedef Documentation

◆ Item

template<typename TContainer >
using CXXIter::trait::Source< TContainer >::Item = typename TContainer::value_type

Type of the item TContainer holds and provides for the iterator.

Definition at line 125 of file Traits.h.

◆ ItemConstRef

template<typename TContainer >
using CXXIter::trait::Source< TContainer >::ItemConstRef = typename TContainer::const_reference

Type of the item TContainer holds and provides for the iterator, in const referenced form.

Definition at line 133 of file Traits.h.

◆ ItemRef

template<typename TContainer >
using CXXIter::trait::Source< TContainer >::ItemRef = typename TContainer::reference

Type of the item TContainer holds and provides for the iterator, in referenced form.

Definition at line 129 of file Traits.h.

Member Function Documentation

◆ hasNext() [1/2]

template<typename TContainer >
static constexpr bool CXXIter::trait::Source< TContainer >::hasNext ( const TContainer &  container,
ConstIteratorState iter 
)
inlinestaticconstexpr

Checks whether there is a next item in the iteration with the given iter state on the given container.

This is used for CXXIter::SrcCRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
Returns
true when there is another item available, false otherwise.

Definition at line 197 of file Traits.h.

◆ hasNext() [2/2]

template<typename TContainer >
static constexpr bool CXXIter::trait::Source< TContainer >::hasNext ( TContainer &  container,
IteratorState iter 
)
inlinestaticconstexpr

Checks whether there is a next item in the iteration with the given iter state on the given container.

This is used for CXXIter::SrcMov and CXXIter::SrcRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
Returns
true when there is another item available, false otherwise.

Definition at line 189 of file Traits.h.

◆ initIterator() [1/2]

template<typename TContainer >
static constexpr ConstIteratorState CXXIter::trait::Source< TContainer >::initIterator ( const TContainer &  container)
inlinestaticconstexpr

Return an initial IteratorState instance for iteration on the given container.

This is stored within CXXIter's source classes, to hold the iteration's state. This is used for CXXIter::SrcCRef

Parameters
containerContainer on which the source runs.
Returns
Instance of ConstIteratorState

Definition at line 180 of file Traits.h.

◆ initIterator() [2/2]

template<typename TContainer >
static constexpr IteratorState CXXIter::trait::Source< TContainer >::initIterator ( TContainer &  container)
inlinestaticconstexpr

Return an initial IteratorState instance for iteration on the given container.

This is stored within CXXIter's source classes, to hold the iteration's state. This is used for CXXIter::SrcMov and CXXIter::SrcRef

Parameters
containerContainer on which the source runs.
Returns
Instance of IteratorState

Definition at line 172 of file Traits.h.

◆ next() [1/2]

template<typename TContainer >
static constexpr ItemConstRef CXXIter::trait::Source< TContainer >::next ( const TContainer &  container,
ConstIteratorState iter 
)
inlinestaticconstexpr

Return the next item in the iteration with the given iter state on the given container.

This is used for CXXIter::SrcCRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
Returns
The next item from the current iteration.

Definition at line 214 of file Traits.h.

◆ next() [2/2]

template<typename TContainer >
static constexpr ItemRef CXXIter::trait::Source< TContainer >::next ( TContainer &  container,
IteratorState iter 
)
inlinestaticconstexpr

Return the next item in the iteration with the given iter state on the given container.

This is used for CXXIter::SrcMov and CXXIter::SrcRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
Returns
The next item from the current iteration.

Definition at line 206 of file Traits.h.

◆ nextBack() [1/2]

template<typename TContainer >
static constexpr ItemConstRef CXXIter::trait::Source< TContainer >::nextBack ( const TContainer &  container,
ConstIteratorState iter 
)
inlinestaticconstexpr

Return the next item from the back of the iteration with the given iter state on the given container.

Note
Implementing this is optional, since not all containers can support this.

This is used for CXXIter::SrcCRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
Returns
The next item from the back of the current iteration.

Definition at line 283 of file Traits.h.

◆ nextBack() [2/2]

template<typename TContainer >
static constexpr ItemRef CXXIter::trait::Source< TContainer >::nextBack ( TContainer &  container,
IteratorState iter 
)
inlinestaticconstexpr

Return the next item from the back of the iteration with the given iter state on the given container.

Note
Implementing this is optional, since not all containers can support this.

This is used for CXXIter::SrcMov and CXXIter::SrcRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
Returns
The next item from the back of the current iteration.

Definition at line 274 of file Traits.h.

◆ peekNext() [1/2]

template<typename TContainer >
static constexpr ItemConstRef CXXIter::trait::Source< TContainer >::peekNext ( const TContainer &  container,
ConstIteratorState iter 
)
inlinestaticconstexpr

Return the next item in the iteration with the given iter state on the given container, without advancing.

This is used for CXXIter::SrcCRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
Returns
The next item from the current iteration.
Attention
Calling this when hasNext() returns false is undefined behavior!

Definition at line 233 of file Traits.h.

◆ peekNext() [2/2]

template<typename TContainer >
static constexpr ItemRef CXXIter::trait::Source< TContainer >::peekNext ( TContainer &  container,
IteratorState iter 
)
inlinestaticconstexpr

Return the next item in the iteration with the given iter state on the given container, without advancing.

This is used for CXXIter::SrcMov and CXXIter::SrcRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
Returns
The next item from the current iteration.
Attention
Calling this when hasNext() returns false is undefined behavior!

Definition at line 224 of file Traits.h.

◆ sizeHint()

template<typename TContainer >
static constexpr SizeHint CXXIter::trait::Source< TContainer >::sizeHint ( const TContainer &  container)
inlinestaticconstexpr

Report a size hint for a source on the given container.

This injects information about the source's size (element count) into the iterator API.

Parameters
containerContainer for which to generate a size hint.
Returns
A size hint for the given container.

Definition at line 163 of file Traits.h.

◆ skipN() [1/2]

template<typename TContainer >
static constexpr size_t CXXIter::trait::Source< TContainer >::skipN ( const TContainer &  container,
ConstIteratorState iter,
size_t  n 
)
inlinestaticconstexpr

Skip the next n elements from the container.

This is used for CXXIter::SrcCRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
nThe amount of elements to skip.
Returns
The amount of actually skipped elements (e.g. if there were less than n elements remaining).

Definition at line 256 of file Traits.h.

Here is the call graph for this function:

◆ skipN() [2/2]

template<typename TContainer >
static constexpr size_t CXXIter::trait::Source< TContainer >::skipN ( const TContainer &  container,
IteratorState iter,
size_t  n 
)
inlinestaticconstexpr

Skip the next n elements from the container.

This is used for CXXIter::SrcMov and CXXIter::SrcRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
nThe amount of elements to skip.
Returns
The amount of actually skipped elements (e.g. if there were less than n elements remaining).

Definition at line 243 of file Traits.h.

Here is the call graph for this function:

◆ skipNBack() [1/2]

template<typename TContainer >
static constexpr size_t CXXIter::trait::Source< TContainer >::skipNBack ( const TContainer &  container,
ConstIteratorState iter,
size_t  n 
)
inlinestaticconstexpr

Skip the next n elements from the back of this iterator.

This is used for CXXIter::SrcCRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
nThe amount of elements to skip.
Returns
The amount of actually skipped elements (e.g. if there were less than n elements remaining).

Definition at line 306 of file Traits.h.

Here is the call graph for this function:

◆ skipNBack() [2/2]

template<typename TContainer >
static constexpr size_t CXXIter::trait::Source< TContainer >::skipNBack ( const TContainer &  container,
IteratorState iter,
size_t  n 
)
inlinestaticconstexpr

Skip the next n elements from the back of this iterator.

This is used for CXXIter::SrcMov and CXXIter::SrcRef

Parameters
containerContainer on which the current iteration is running.
iterThe current iteration's state structure.
nThe amount of elements to skip.
Returns
The amount of actually skipped elements (e.g. if there were less than n elements remaining).

Definition at line 293 of file Traits.h.

Here is the call graph for this function:

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