CXXIter 0.2
Loading...
Searching...
No Matches
CXXIter Namespace Reference

CXXIter. More...

Namespaces

namespace  fn
 Namespace that contains helper functions providing commonly required functionality when working with CXXIter.
 
namespace  trait
 Trait namespace. This namespaces contains all public traits that cover all of the iterator's inner workings.
 

Classes

class  Generator
 Generator that C++20 coroutines passed to CXXIter::IterApi::generateFrom() have to return. This generator supports exceptions, co_yield for producing an arbitrary amount of elements, and can take references as results from coroutines - as long as they live long enough until used. More...
 
class  IterApi
 Public Iterator API surface. More...
 
class  IterValue
 Container that is used to pass elements through CXXIter's iterator pipelines. More...
 
struct  SizeHint
 Structure holding the bounds of a CXXIter iterator's estimated length. More...
 
class  SrcCRef
 CXXIter iterator source that immutably borrows the input item source, and passes immutable references to the items of the source through the iterator. More...
 
class  SrcMov
 CXXIter iterator source that takes over the input item source, and moves its items through the element stream, essentially "consuming" them. More...
 
class  SrcRef
 CXXIter iterator source that mutably borrows the input item source, and passes mutable references to the items of the source through the iterator. More...
 

Typedefs

template<typename TItem , const size_t CHUNK_SIZE>
using DynamicChunk = std::conditional_t< std::is_reference_v< TItem >, std::vector< std::reference_wrapper< TItem > >, std::vector< TItem > >
 
template<typename TItem , const size_t CHUNK_SIZE>
using ExactChunk = std::conditional_t< std::is_reference_v< TItem >, std::array< std::reference_wrapper< std::remove_reference_t< TItem > >, CHUNK_SIZE >, std::array< TItem, CHUNK_SIZE > >
 

Enumerations

enum class  SortOrder { ASCENDING , DESCENDING }
 SortOrder for the item sorting methods. More...
 
enum class  StatisticNormalization { N , N_MINUS_ONE }
 Normalization variant to use while calculating statistics (mean / stddev / ...) More...
 

Functions

Source Entry Points
template<typename TContainer >
requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
constexpr SrcMov< std::remove_cvref_t< TContainer > > from (TContainer &&container)
 Construct a CXXIter move source from the given container. More...
 
template<typename TContainer >
requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
constexpr SrcRef< std::remove_cvref_t< TContainer > > from (TContainer &container)
 Construct a CXXIter mutable-reference source from the given container. More...
 
template<typename TContainer >
requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
constexpr SrcCRef< std::remove_cvref_t< TContainer > > from (const TContainer &container)
 Construct a CXXIter const-reference source from the given container. More...
 
Generator Entry Points
template<typename TItem >
constexpr Empty< TItem > empty ()
 Constructs an empty iterator yielding no items. More...
 
template<std::invocable<> TGeneratorFn>
requires util::is_optional<std::invoke_result_t<TGeneratorFn>>
constexpr auto fromFn (TGeneratorFn generatorFn)
 Generator source that takes a generatorFn, each invocation of which produces one element for the resulting iterator. More...
 
template<GeneratorFunction TGeneratorFn>
auto generate (TGeneratorFn generatorFn)
 Generator source that produces a new iterator over the elements produced by the given generatorFn - which is a c++20 coroutine yielding elements using co_yield. More...
 
template<typename TItem >
constexpr Repeater< TItem > repeat (const TItem &item, std::optional< size_t > cnt={})
 Construct a CXXIter iterator, by repeating the given item cnt times. More...
 
template<typename TValue >
constexpr Range< TValue > range (TValue from, TValue to, TValue step=1)
 Construct a CXXIter iterator that yields all elements in the range between [from, to] (inclusive both edges), using the given step between elements. More...
 

Detailed Description

Typedef Documentation

◆ DynamicChunk

template<typename TItem , const size_t CHUNK_SIZE>
using CXXIter::DynamicChunk = typedef std::conditional_t< std::is_reference_v<TItem>, std::vector<std::reference_wrapper<TItem> >, std::vector<TItem> >

Definition at line 14 of file Chunked.h.

◆ ExactChunk

template<typename TItem , const size_t CHUNK_SIZE>
using CXXIter::ExactChunk = typedef std::conditional_t< std::is_reference_v<TItem>, std::array<std::reference_wrapper<std::remove_reference_t<TItem> >, CHUNK_SIZE>, std::array<TItem, CHUNK_SIZE> >

Definition at line 14 of file ChunkedExact.h.

Enumeration Type Documentation

◆ SortOrder

enum class CXXIter::SortOrder
strong

SortOrder for the item sorting methods.

Definition at line 22 of file Common.h.

◆ StatisticNormalization

Normalization variant to use while calculating statistics (mean / stddev / ...)

Enumerator

Use when the mean, variance, stddev is calculated with the COMPLETE population.

N_MINUS_ONE 

Use when the mean, variance, stddev is calculated from a sample of the population.

Definition at line 34 of file Common.h.

Function Documentation

◆ empty()

template<typename TItem >
constexpr Empty< TItem > CXXIter::empty ( )
constexpr

Constructs an empty iterator yielding no items.

Returns
An empty iterator that yields no items.

Usage Example:

CXXIter::IterValue<std::string> output = CXXIter::empty<std::string>()
.next();
// output == None
Container that is used to pass elements through CXXIter's iterator pipelines.
Definition: IterValue.h:19

Definition at line 2236 of file CXXIter.h.

◆ from() [1/3]

template<typename TContainer >
requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
constexpr SrcCRef< std::remove_cvref_t< TContainer > > CXXIter::from ( const TContainer &  container)
constexpr

Construct a CXXIter const-reference source from the given container.

This constructs a const-reference source. This guarantees the given container to stay untouched.

Parameters
containerContainer to construct a CXXIter source from.
Returns
CXXIter const-reference source from the given container.

Definition at line 2214 of file CXXIter.h.

◆ from() [2/3]

template<typename TContainer >
requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
constexpr SrcMov< std::remove_cvref_t< TContainer > > CXXIter::from ( TContainer &&  container)
constexpr

Construct a CXXIter move source from the given container.

This constructs a move source, which will move the items from the given container into the iterator.

Parameters
containerContainer to construct a CXXIter source from.
Returns
CXXIter move source from the given container.

Definition at line 2188 of file CXXIter.h.

◆ from() [3/3]

template<typename TContainer >
requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
constexpr SrcRef< std::remove_cvref_t< TContainer > > CXXIter::from ( TContainer &  container)
constexpr

Construct a CXXIter mutable-reference source from the given container.

This constructs a mutable-reference source. This allows the iterator to modify the elements in the given container.

Parameters
containerContainer to construct a CXXIter source from.
Returns
CXXIter mutable-reference source from the given container.

Definition at line 2201 of file CXXIter.h.

◆ fromFn()

template<std::invocable<> TGeneratorFn>
requires util::is_optional<std::invoke_result_t<TGeneratorFn>>
constexpr auto CXXIter::fromFn ( TGeneratorFn  generatorFn)
constexpr

Generator source that takes a generatorFn, each invocation of which produces one element for the resulting iterator.

Parameters
generatorFnGenerator that returns an optional value. If the optional is None, the resulting iterator ends.
Returns
CXXIter iterator whose elements are produced by the calls to the given generatorFn.

You could for example also use this to pull messages from a socket.

Usage Example:

  • Simple endless generator producing monotonically increasing numbers
    size_t generatorState = 0;
    std::function<std::optional<size_t>()> generatorFn = [generatorState]() mutable {
    return (generatorState++);
    };
    std::vector<size_t> output = CXXIter::fromFn(generatorFn)
    .take(100)
    .collect<std::vector>();
    // output == {0, 1, 2, 3, ..., 99}
    constexpr auto fromFn(TGeneratorFn generatorFn)
    Generator source that takes a generatorFn, each invocation of which produces one element for the resu...
    Definition: CXXIter.h:2261

Definition at line 2261 of file CXXIter.h.

◆ generate()

template<GeneratorFunction TGeneratorFn>
auto CXXIter::generate ( TGeneratorFn  generatorFn)

Generator source that produces a new iterator over the elements produced by the given generatorFn - which is a c++20 coroutine yielding elements using co_yield.

Parameters
generatorFnC++20 generator coroutine function yielding elements using co_yield. The function must produces a generator of type CXXIter::Generator whose template parameter is set to the produced element type.
Returns
CXXIter iterator over the elements produced by the c++20 coroutine given in generatorFn.

Usage Example:

  • Simple generator example producing all integer numbers from 0 to 1000 as std::string
    std::vector<std::string> output = CXXIter::generate(
    for(size_t i = 0; i < 1000; ++i) {
    co_yield std::to_string(i);
    }
    }
    ).collect<std::vector>();
    // output == {0, 1, 2, ..., 1000}
    Generator that C++20 coroutines passed to CXXIter::IterApi::generateFrom() have to return....
    Definition: Generator.h:21
    auto generate(TGeneratorFn generatorFn)
    Generator source that produces a new iterator over the elements produced by the given generatorFn - w...
    Definition: CXXIter.h:2289

Definition at line 2289 of file CXXIter.h.

◆ range()

template<typename TValue >
constexpr Range< TValue > CXXIter::range ( TValue  from,
TValue  to,
TValue  step = 1 
)
constexpr

Construct a CXXIter iterator that yields all elements in the range between [from, to] (inclusive both edges), using the given step between elements.

Parameters
fromStart of the range of elements to generate.
toEnd of the range of elements to generate.
stepStepwidth to use between the generated elements.
Returns
CXXIter iterator returning elements from the requested range [from, to] using the given step width.

Usage Example:

  • For an integer type:
    std::vector<int> output = CXXIter::range(1, 7, 2)
    .collect<std::vector>();
    // output == {1, 3, 5, 7}
    constexpr Range< TValue > range(TValue from, TValue to, TValue step=1)
    Construct a CXXIter iterator that yields all elements in the range between [from, to] (inclusive both...
    Definition: CXXIter.h:2341
  • For a float type
    std::vector<float> output = CXXIter::range(0.0f, 1.1f, 0.25f)
    .collect<std::vector>();
    // output == {0.0f, 0.25f, 0.5f, 0.75f, 1.0f}

Definition at line 2341 of file CXXIter.h.

Here is the call graph for this function:

◆ repeat()

template<typename TItem >
constexpr Repeater< TItem > CXXIter::repeat ( const TItem &  item,
std::optional< size_t >  cnt = {} 
)
constexpr

Construct a CXXIter iterator, by repeating the given item cnt times.

Parameters
itemItem to use as repeated element of the generated element.
cntOptional amount of repetitions of item the generated iterator should consist of. If none, the iterator will repeat the item forever.
Returns
CXXIter iterator that returns the given item cnt times.

Usage Example:

std::vector<int> item = {1, 3, 3, 7};
std::vector<int> output = CXXIter::repeat(item, 3)
.flatMap()
.collect<std::vector>();
// output == {1, 3, 3, 7, 1, 3, 3, 7, 1, 3, 3, 7}
constexpr Repeater< TItem > repeat(const TItem &item, std::optional< size_t > cnt={})
Construct a CXXIter iterator, by repeating the given item cnt times.
Definition: CXXIter.h:2313

Definition at line 2313 of file CXXIter.h.