CXXIter 0.2
|
Public Iterator API surface. More...
#include <CXXIter.h>
Classes | |
class | iterator |
C++ iterator implementation for a CXXIter chain. More... | |
Public Types | |
using | Iterator = trait::Iterator< TSelf > |
Type of the trait::Iterator implemenation for this. More... | |
using | Item = typename Iterator::Item |
Type of the elements of this iterator. (Can be references) More... | |
using | ItemOwned = std::remove_cvref_t< Item > |
Owned Type of the elements of this iterator. (References removed). More... | |
Public Member Functions | |
iterator | begin () |
begin() method, part of C++'s iterator interface More... | |
iterator | end () |
end() method, part of C++'s iterator interface More... | |
constexpr SizeHint | sizeHint () const |
Get the bounds on the remaining length of this iterator, estimated from the source and all of the chained iterations on it. More... | |
constexpr size_t | size () const |
Get this iterator's exact size. More... | |
constexpr IterValue< Item > | next () |
Get the next element from this iterator (if any), wrapped in a CXXIter::IterValue<>. More... | |
constexpr void | advanceBy (size_t n) |
Advance the iterator by n elements. More... | |
constexpr IterValue< Item > | nextBack () |
Get the next element from the back of this iterator (if any), wrapped in a CXXIter::IterValue<>. More... | |
Consumers | |
template<typename TUseFn > | |
constexpr void | forEach (TUseFn useFn) |
Consumer that calls the given function useFn for each of the elements in this iterator. More... | |
template<template< typename... > typename TTargetContainer, typename... TTargetContainerArgs> | |
constexpr auto | collect () |
Consumer that collects all elements from this iterator in a new container of type TTargetContainer . More... | |
template<typename TTargetContainer > | |
constexpr TTargetContainer | collect () |
Consumer that collects all elements from this iterator in a new container of type TTargetContainer . More... | |
template<typename TTargetContainer > | |
constexpr void | collectInto (TTargetContainer &container) |
Consumer that collects all elements from this iterator into the given container . More... | |
template<typename TResult , std::invocable< TResult &, Item && > FoldFn> | |
constexpr TResult | fold (TResult startValue, FoldFn foldFn) |
Consumer that executes the given foldFn for each item in this iterator, to apply to a working value, which is passed on and passed as second argument to the next call to foldFn . More... | |
template<std::invocable< const ItemOwned & > TPredicateFn> requires std::same_as<std::invoke_result_t<TPredicateFn, const ItemOwned&>, bool> | |
constexpr bool | all (TPredicateFn predicateFn) |
Tests if all elements of this iterator match the given predicateFn . More... | |
constexpr bool | all () |
Tests if all elements of this iterator yield the value true when casted to bool . More... | |
template<std::invocable< const ItemOwned & > TPredicateFn> | |
constexpr bool | any (TPredicateFn predicateFn) |
Tests if any of the elements of this iterator match the given predicateFn . More... | |
constexpr bool | any () |
Tests if any of the elements of this iterator yield the value true when casted to bool . More... | |
constexpr std::optional< size_t > | findIdx (const ItemOwned &searchItem) |
Search for the given searchItem within the items of this iterator, and return the index of the first item from the iterator that is equal to the given searchItem . More... | |
template<std::invocable< const ItemOwned & > TFindFn> | |
constexpr std::optional< size_t > | findIdx (TFindFn findFn) |
Search for the iterator with the given findFn , and return the index of the element from this iterator, for which the findFn returned true the first time. More... | |
template<std::invocable< const ItemOwned & > TFindFn> | |
constexpr IterValue< Item > | find (TFindFn findFn) |
Searches for an element of this iterator, that satisfies the given findFn predicate. More... | |
constexpr size_t | count () |
Consumer that counts the elements in this iterator. More... | |
template<std::invocable< const ItemOwned & > TPredicateFn> | |
constexpr size_t | count (TPredicateFn predicateFn) |
Consumer that counts the elements in this iterator, for which the given predicateFn returns true . More... | |
constexpr size_t | count (const ItemOwned &countItem) |
Consumer that counts the occurences of countItem within this iterator. More... | |
template<typename TResult = ItemOwned> requires requires(TResult res, Item item) { { res += item }; } | |
constexpr TResult | sum (TResult startValue=TResult()) |
Consumer that calculates the sum of all elements from this iterator. More... | |
std::string | stringJoin (const std::string &separator) |
Consumer that concatenates the elements of this iterator to a large std::string , where each element is separated by the specified separator . More... | |
template<StatisticNormalization NORM = StatisticNormalization::N, typename TResult = ItemOwned, typename TCount = ItemOwned> | |
constexpr std::optional< TResult > | mean (TResult sumStart=TResult()) |
Consumer that calculates the mean of all elements of this iterator. More... | |
template<StatisticNormalization NORM = StatisticNormalization::N, typename TResult = ItemOwned, typename TCount = ItemOwned> | |
constexpr std::optional< TResult > | variance () |
Consumer that calculates the variance of all elements of this iterator. More... | |
template<StatisticNormalization NORM = StatisticNormalization::N, typename TResult = ItemOwned, typename TCount = ItemOwned> | |
constexpr std::optional< TResult > | stddev () |
Consumer that calculates the standard deviation of all elements of this iterator. More... | |
constexpr IterValue< Item > | min () |
Consumer that yields the smallest element from this iterator. More... | |
constexpr std::optional< size_t > | minIdx () |
Consumer that yields the index of the smallest element within this iterator. More... | |
constexpr IterValue< Item > | max () |
Consumer that yields the largest element from this iterator. More... | |
constexpr std::optional< size_t > | maxIdx () |
Consumer that yields the index of the largest element within this iterator. More... | |
template<typename TCompValueExtractFn > requires requires(const std::invoke_result_t<TCompValueExtractFn, Item&&>& a, std::remove_cvref_t<decltype(a)> ownedA) { { a < a }; { ownedA = ownedA }; } | |
constexpr IterValue< Item > | minBy (TCompValueExtractFn compValueExtractFn) |
Consumer that yields the smallest element from this iterator. Comparison of items is done using the comparison values returned by invoking the given compValueExtractFn on each element. More... | |
template<typename TCompValueExtractFn > requires requires(const std::invoke_result_t<TCompValueExtractFn, Item&&>& a) { { a < a }; } | |
constexpr std::optional< size_t > | minIdxBy (TCompValueExtractFn compValueExtractFn) |
Consumer that yields the index of the smallest element from this iterator. Comparison of items is done using the comparison values returned by invoking the given compValueExtractFn on each element. More... | |
template<typename TMaxValueExtractFn > requires requires(const std::invoke_result_t<TMaxValueExtractFn, Item&&>& a, std::remove_cvref_t<decltype(a)> ownedA) { { a > a }; { ownedA = ownedA }; } | |
constexpr IterValue< Item > | maxBy (TMaxValueExtractFn compValueExtractFn) |
Consumer that yields the largest element from this iterator. Comparison of items is done using the comparison values returned by invoking the given compValueExtractFn on each element. More... | |
template<typename TMaxValueExtractFn > requires requires(const std::invoke_result_t<TMaxValueExtractFn, Item&&>& a, std::remove_cvref_t<decltype(a)> ownedA) { { a > a }; { ownedA = ownedA }; } | |
constexpr std::optional< size_t > | maxIdxBy (TMaxValueExtractFn compValueExtractFn) |
Consumer that yields the index of the largest element from this iterator. Comparison of items is done using the comparison values returned by invoking the given TCompValueExtractFn on each element. More... | |
constexpr IterValue< Item > | last () |
Consumer that yields the last element of this iterator. More... | |
constexpr IterValue< Item > | nth (size_t n) |
Return the {n}-th element from this iterator (if available). More... | |
Chainers | |
template<typename TItemOutput > | |
constexpr op::Caster< TSelf, TItemOutput > | cast () |
Constructs a new iterator that casts the elements of this iterator to the type requested by TItemOutput . More... | |
constexpr auto | copied () |
Constructs a new iterator that copies the elements of this iterator. More... | |
constexpr auto | indexed () |
Constructs a new iterator that tags each element of this iterator with the corresponding index, stored in a std::pair . More... | |
constexpr op::FlagLast< TSelf > | flagLast () |
Constructs a new iterator that tags each element with a boolean value specifying whether the element is the last one in the iterator. Boolean and actual iterator element are stored in a std::pair . More... | |
template<std::invocable< const ItemOwned & > TFilterFn> | |
constexpr op::Filter< TSelf, TFilterFn > | filter (TFilterFn filterFn) |
Constructs a new iterator that only contains the elements from this iterator, for which the given filterFn returned true . More... | |
template<std::invocable< const ItemOwned & > TMapFn> requires util::is_hashable<std::invoke_result_t<TMapFn, const ItemOwned&>> | |
constexpr op::Unique< TSelf, TMapFn > | unique (TMapFn mapFn) |
Constructs a new iterator that only contains every element of the input iterator only once. More... | |
constexpr auto | unique () |
Constructs a new iterator that only contains every element of the input iterator only once. More... | |
constexpr op::Reverse< TSelf > | reverse () |
Constructs a new iterator that provides the elements of this iterator in reverse order. More... | |
template<const size_t CHUNK_SIZE> | |
constexpr op::Chunked< TSelf, CHUNK_SIZE > | chunked () |
Create new iterator that collects elements from this iterator in chunks of size up to CHUNK_SIZE , which then constitue the elements of the new iterator. More... | |
template<const size_t CHUNK_SIZE, const size_t STEP_SIZE = CHUNK_SIZE> | |
constexpr op::ChunkedExact< TSelf, CHUNK_SIZE, STEP_SIZE > | chunkedExact () |
Create new iterator that collects elements from this iterator in exact-sized chunks of CHUNK_SIZE , which then constitue the elements of the new iterator. More... | |
template<std::invocable< Item && > TMapFn> | |
constexpr auto | map (TMapFn mapFn) |
Creates an iterator that uses the given mapFn to map each element from this iterator to elements of the new iterator. More... | |
template<std::invocable< Item && > TFlatMapFn> | |
constexpr auto | flatMap (TFlatMapFn mapFn) |
Creates an iterator that works like map(), but flattens nested containers. More... | |
template<GeneratorFromFunction< Item > TGeneratorFn> | |
constexpr auto | generateFrom (TGeneratorFn generatorFn) |
Creates a new iterator containing the items that the given generator produces for each element in this iterator. More... | |
constexpr auto | flatMap () |
Creates an iterator that flattens the iterable elements of this iterator. More... | |
template<std::invocable< Item & > TModifierFn> | |
constexpr op::InplaceModifier< TSelf, TModifierFn > | modify (TModifierFn modifierFn) |
Allows to inspect and modify each item in-place, that passes through this iterator. More... | |
template<std::invocable< ItemOwned && > TFilterMapFn> requires util::is_optional<std::invoke_result_t<TFilterMapFn, ItemOwned&&>> | |
constexpr auto | filterMap (TFilterMapFn filterMapFn) |
Creates a new iterator that filters and maps items from this iterator. More... | |
constexpr op::SkipN< TSelf > | skip (size_t cnt) |
Creates an iterator that skips the first cnt elements from this iterator, before it yields the remaining items. More... | |
template<std::invocable< const Item & > TSkipPredicate> | |
constexpr op::SkipWhile< TSelf, TSkipPredicate > | skipWhile (TSkipPredicate skipPredicate) |
Creates an iterator that skips the first elements of this iterator, for which the given skipPredicate returns true . More... | |
constexpr op::TakeN< TSelf > | take (size_t cnt) |
Creates an iterator that yields at most the first cnt elements from this iterator. More... | |
template<std::invocable< const Item & > TTakePredicate> requires std::is_same_v<std::invoke_result_t<TTakePredicate, const Item&>, bool> | |
constexpr auto | takeWhile (TTakePredicate takePredicate) |
Creates an iterator that yields the first elements of this iterator, for which the given takePredicate returns true . More... | |
constexpr auto | stepBy (size_t stepWidth) |
Creates an iterator with the requested stepWidth from this iterator. More... | |
template<typename TOtherIterator > | |
constexpr op::Zipper< TSelf, std::pair, TOtherIterator > | zip (TOtherIterator &&otherIterator) |
"Zips up" two CXXIter iterators into a single iterator over pairs from both iterators. More... | |
template<typename... TOtherIterators> requires (CXXIterIterator<TOtherIterators> && ...) && (!std::disjunction_v< std::is_reference<typename trait::Iterator<TOtherIterators>::Item>... > && !IS_REFERENCE) | |
constexpr op::Zipper< TSelf, std::tuple, TOtherIterators... > | zipTuple (TOtherIterators &&... otherIterators) |
"Zips up" an arbitrary amount of CXXIter iterators into a single iterator over std::tuple<> from both iterators. More... | |
template<typename TOtherIterator > requires std::is_same_v<Item, typename TOtherIterator::Item> | |
constexpr op::Chainer< TSelf, TOtherIterator > | chain (TOtherIterator &&otherIterator) |
Chains this iterator with the given otherIterator , resulting in a new iterator that first yields the elements of this iterator, and then the ones from the otherIterator . More... | |
template<typename... TOtherIterators> requires (CXXIterIterator<TOtherIterators> && ...) && (util::are_same_v<Item, typename TOtherIterators::Item...>) | |
constexpr op::Alternater< TSelf, TOtherIterators... > | alternate (TOtherIterators &&... otherIterators) |
Alternating the elements of this iterator with the ones from the other given iterator(s). More... | |
template<typename TOtherIterator > requires (std::is_same_v<Item, typename TOtherIterator::Item>) | |
constexpr op::Intersperser< TSelf, TOtherIterator > | intersperse (TOtherIterator &&otherIterator) |
Draw elements from the given otherIterator and use the returned elements as separators between the elements of this iterator. More... | |
template<std::invocable< const Item & > TGroupIdentifierFn> requires util::is_hashable<std::invoke_result_t<TGroupIdentifierFn, const Item&>> | |
constexpr auto | groupBy (TGroupIdentifierFn groupIdentFn) |
Groups the elements of this iterator according to the values returned by the given groupidentFn . More... | |
template<bool STABLE, std::invocable< const ItemOwned &, const ItemOwned & > TCompareFn> | |
constexpr auto | sort (TCompareFn compareFn) |
Creates a new iterator that takes the items from this iterator, and passes them on sorted, using the supplied compareFn . More... | |
template<SortOrder ORDER = SortOrder::ASCENDING, bool STABLE = false> requires requires(const ItemOwned& a) { { a < a }; { a > a }; } | |
constexpr auto | sort () |
Creates a new iterator that takes the items from this iterator, and passes them on sorted. More... | |
template<SortOrder ORDER = SortOrder::ASCENDING, bool STABLE = false, std::invocable< const ItemOwned & > TSortValueExtractFn> requires requires(const std::invoke_result_t<TSortValueExtractFn, const ItemOwned&>& a) { { a < a }; { a > a }; } | |
constexpr auto | sortBy (TSortValueExtractFn sortValueExtractFn) |
Creates a new iterator that takes the items from this iterator, and passes them on sorted. More... | |
Public Iterator API surface.
using CXXIter::IterApi< TSelf >::Item = typename Iterator::Item |
using CXXIter::IterApi< TSelf >::ItemOwned = std::remove_cvref_t<Item> |
using CXXIter::IterApi< TSelf >::Iterator = trait::Iterator<TSelf> |
Type of the trait::Iterator implemenation for this.
|
inlineconstexpr |
Advance the iterator by n elements.
If possible, this is a O(1) operation. Some iterator pipeline elements make that impossible though. In these cases, the implementation falls back to pulling n elements and dropping them.
n | The amount of elements to advance the iterator by. |
Usage Example:
Definition at line 195 of file CXXIter.h.
|
inlineconstexpr |
Tests if all elements of this iterator yield the value true
when casted to bool
.
This is an overload of all(TPredicateFn) for item types that support being casted to bool
.
true
when all elements of this iterator yielded the value true
when casted to a bool
, false
otherwise.Usage Example:
true
when casted to bool
. true
when casted to bool
.
|
inlineconstexpr |
Tests if all elements of this iterator match the given predicateFn
.
predicateFn | Predicate to test all items of this iterator against. |
true
when the given predicateFn
returned true
for all elements of this iterator, false
otherwise.Usage Example: (Using the following predicate)
true
for all elements: true
for all elements: Definition at line 396 of file CXXIter.h.
|
inlineconstexpr |
Alternating the elements of this iterator with the ones from the other given iterator(s).
Everytime an element is polled from the iterator resulting from this call, an element from the current input iterator is forwarded. Then, the current input iterator is switched to the next input. The resulting iterator ends, when the currently active input has no more elements.
otherIterators | An arbitrary amount of iterators to alternate the elements of this iterator with. |
Usage Example:
|
inlineconstexpr |
Tests if any of the elements of this iterator yield the value true
when casted to bool
.
This is an overload of any(TPredicateFn) for item types that support being casted to bool
.
true
when any of the elements of this iterator yielded the value true
when casted to a bool
, false
otherwise.Usage Example:
true
when casted to bool
. true
when casted to bool
.
|
inlineconstexpr |
Tests if any of the elements of this iterator match the given predicateFn
.
predicateFn | Predicate to test all items of this iterator against. |
true
when the given predicateFn
returned true
for any of the elements of this iterator, false
otherwise.Usage Example: (Using the following predicate)
predicateFn
returns false
for all elements: predicateFn
returns true
for any of the elements: Definition at line 472 of file CXXIter.h.
|
inline |
|
inlineconstexpr |
Constructs a new iterator that casts the elements of this iterator to the type requested by TItemOutput
.
This iterator applies the requested type cast to TItemOutput
using static_cast<>
.
TItemOutput | Type to cast the elements of this iterator to. |
TItemOutput
.Usage Example:
|
inlineconstexpr |
Chains this iterator with the given otherIterator
, resulting in a new iterator that first yields the elements of this iterator, and then the ones from the otherIterator
.
otherIterator | Other iterator whose elements should be "appended" to the elements of this iterator. |
otherIterator
. otherIterator
have to be identical.Usage Example:
|
inlineconstexpr |
Create new iterator that collects elements from this iterator in chunks of size up to CHUNK_SIZE
, which then constitue the elements of the new iterator.
Chunks are of up to CHUNK_SIZE
elements in size. If the amount of items in the iterator are not dividable by the requested CHUNK_SIZE
the last chunk will be smaller.
CHUNK_SIZE | Amount of elements from this iterator, that get collected to one chunk. |
Usage Example:
CHUNK_SIZE
: CHUNK_SIZE
:
|
inlineconstexpr |
Create new iterator that collects elements from this iterator in exact-sized chunks of CHUNK_SIZE
, which then constitue the elements of the new iterator.
A chunk is only committed in the new iterator, after it was filled completely. That means, that if the amount of elements in this iterator do not evenly divide up to CHUNK_SIZE
sized chunks, the last couple of elements that fail to fill a complete chunk will be dropped.
Where possible (for contiguous memory sources, such as std::vector<>
or std::array<>
), this method avoids creating copies of the elements, and instead forwards an std::array<>&
pointing at the memory position of the current chunk's start. This essentially allows working directly on the source's memory region. If this isn't possible because the source or any previous chainer method calls make direct source memory inaccessible, this will fallback to using a temporary buffer, able to hold an entire chunk, that is filled by pulling elements from this iterator into the buffer, before a const reference to the buffer is passed onwards.
CHUNK_SIZE | Amount of elements from this iterator, that get collected to one chunk. |
STEP_SIZE | Controls the step-size between chunks. Per default, this is set to the same as CHUNK_SIZE , so the produced chunks are directly adjacent. If this is set to a value smaler than CHUNK_SIZE , the generated chunks will overlap. If this is set to a value higher than CHUNK_SIZE , the generated chunks will have gaps in between (those items are dropped). |
CHUNK_SIZE
) chunks of elements from this iterator as elements.std::array<...>&
where the reference points directly to the contiguous memory source's memory region - irrespecting of whether this iterator's elements are referenced or owned/copied. Changing the elements in these chunk references will thus directly change the elements in the source.chunkedExact()
)std::array<std::reference_wrapper<...>>&
, in order to preserve the ability to modify the elements in-place. In case this is unwanted, prepend the call to chunkedExact()
with a call to the copied()
chainer method.const
std::array<...>&Contiguous Memory
CHUNK_SIZE
: CHUNK_SIZE
: Non-Contiguous Memory
|
inlineconstexpr |
Consumer that collects all elements from this iterator in a new container of type TTargetContainer
.
TTargetContainer | Type-Template for the target container that the elements from this iterator should be collected into. The first template parameter of this Type-Template has to take the type of the elements. |
TTargetContainerArgs... | Optional additional type attributes to pass on to the target container. These are appended to the item value type, which is automatically supplied. |
TTargetContainer
with all the elements of this iterator collected into.Usage Example:
With Additional container type parameters:
|
inlineconstexpr |
Consumer that collects all elements from this iterator in a new container of type TTargetContainer
.
TTargetContainer | Fully qualified type of the target container to collect the items of this iterator into. |
TTargetContainer
with all the elements of this iterator collected into.Usage Example:
Definition at line 306 of file CXXIter.h.
|
inlineconstexpr |
Consumer that collects all elements from this iterator into the given container
.
container | to collect this iterator's elements into. |
Before appending this iterator's elements to the elements already present in the given container
, the collector tries to resize the container
to its current size + this iterator's expected amount of items.
Usage Example:
|
inlineconstexpr |
Constructs a new iterator that copies the elements of this iterator.
This function essentially converts an iterator that is passing elements by reference, to an iterator that is passing elements by value midway.
Usage Example:
Definition at line 1277 of file CXXIter.h.
|
inlineconstexpr |
Consumer that counts the elements in this iterator.
Usage Example:
Definition at line 621 of file CXXIter.h.
|
inlineconstexpr |
Consumer that counts the occurences of countItem
within this iterator.
countItem | Item for which to count the amount of occurences within this iterator. |
countItem
within this iterator.Usage Example:
|
inlineconstexpr |
Consumer that counts the elements in this iterator, for which the given predicateFn
returns true
.
predicateFn | Predicate that is run for each element of this iterator, to determine whether it should contribute to the resulting count. |
predicateFn
returned true
.Usage Example:
Definition at line 642 of file CXXIter.h.
|
inline |
|
inlineconstexpr |
Constructs a new iterator that only contains the elements from this iterator, for which the given filterFn
returned true
.
filterFn | Function that decides which element of this iterator to yield in the newly created iterator. |
filterFn
returns true
.Usage Example:
|
inlineconstexpr |
Creates a new iterator that filters and maps items from this iterator.
filterMapFn | Function that maps the incomming items to an optional mapped value. If it returns an empty std::optional<> the element is filtered. If it returns an std::optional<> with a value, that item is yielded from the resulting iterator. |
filterMapFn
returned a mapped value.Usage Example:
|
inlineconstexpr |
Searches for an element of this iterator, that satisfies the given findFn
predicate.
findFn | Predicate used to search for an element in this iterator. |
findFn
predicate returned true
(if any), otherwise empty.Usage Example:
Definition at line 602 of file CXXIter.h.
|
inlineconstexpr |
Search for the given searchItem
within the items of this iterator, and return the index of the first item from the iterator that is equal to the given searchItem
.
searchItem | Item to search for in the iterator. |
searchItem
in the iterator, if found.Usage Example:
|
inlineconstexpr |
Search for the iterator with the given findFn
, and return the index of the element from this iterator, for which the findFn
returned true
the first time.
findFn | Lambda invoked for each element of this stream, to determined whether it is the item that is searched for. |
findFn
returned true
.Usage Example:
Definition at line 565 of file CXXIter.h.
|
inlineconstexpr |
Constructs a new iterator that tags each element with a boolean value specifying whether the element is the last one in the iterator. Boolean and actual iterator element are stored in a std::pair
.
std::pair
with the iterator element in the first, and a boolean flag specifying whether the element will be the last one in the second slot.Usage Example:
|
inlineconstexpr |
Creates an iterator that flattens the iterable elements of this iterator.
This works by pulling elements from this iterator, turning them into iterators themselves, and merging them into the stream of the resulting iterator. This only resolves one layer of nesting, and the elements of this iterator have to be supported by CXXIter (by a fitting SourceTrait
implementation).
Usage Example:
Definition at line 1712 of file CXXIter.h.
|
inlineconstexpr |
Creates an iterator that works like map(), but flattens nested containers.
This works by pulling elements from this iterator, passing them to the given mapFn
, and then taking the returned values to turn them into iterators themselves, to merge them into the stream of the resulting iterator. This only resolves one layer of nesting, and values returned by mapFn
have to be supported by CXXIter (by a fitting SourceTrait
implementation).
mapFn | Function that returns a nesting container, that should be merged into the returned iterator's stream. |
Usage Example:
|
inlineconstexpr |
Consumer that executes the given foldFn
for each item in this iterator, to apply to a working value, which is passed on and passed as second argument to the next call to foldFn
.
startValue | The initial value of the working value passed to foldFn . |
foldFn | Function called for each element in this iterator, passed the current workingValue and an element from this iterator. |
foldFn
for the last element from this iterator.Usage Example:
Definition at line 353 of file CXXIter.h.
|
inlineconstexpr |
Consumer that calls the given function useFn
for each of the elements in this iterator.
useFn | Function called for each of the elements in this iterator. |
Usage Example:
Definition at line 241 of file CXXIter.h.
|
inlineconstexpr |
Creates a new iterator containing the items that the given generator produces for each element in this iterator.
Conceptually, this method is very similar to flatMap() since it allows to take one element from this iterator, and returning an arbitrary amount of new elements into the resulting iterator. A big difference is, that with generateFrom(), elements can be produced on the fly using c++20 coroutines, while with flatMap() they need to be present in a supported container at once - taking up memory. The given generatorFn
is run for each element in this iterator, producing a generator. This generator is then driven to completion, piping every element it produced into the resulting iterator.
generatorFn | Generator function that is executed for each element of this iterator. This function can use co_yield to produce as many elements as it wants. Its return value has to be explicitly specified as CXXIter::Generator with the generated type as template parameter. |
generatorFn
. The generator must take the elements of the stream by-value (copied). If the elements in the stream are moved through the stream, the generatorFn
must take them as their owned type. If the elements are passed as references through the stream, the generatorFn
can take them as references. If you are getting spurious SEGFAULTs - check your parameter types!Usage Example:
The example shows a generator that repeats the strings from the source, depending on the string's lengths. Special attention in these examples should be mainly on the parameter types, as well as the explicitly specified return values of the given generator functions.
std::string
by move. So the type the generator has to take as parameter is an owned std::string
. std::string
references. So the type the generator takes can either be a const std::string
reference (because they don't reference something temporary, but are references from the permanent source) - or as an owned std::string
.
|
inlineconstexpr |
Groups the elements of this iterator according to the values returned by the given groupidentFn
.
groupIdentFn | Function called for each element from this iterator, to determine the grouping value, that is then used to identify the group an item belongs to. The type returned by this function has to implement std::hash<> . |
std::pair<>
with the group identifier as first value, and a std::vector
of all values in the group as second value. Usage Example:
|
inlineconstexpr |
Constructs a new iterator that tags each element of this iterator with the corresponding index, stored in a std::pair
.
std::pair
with an element index in the first, and the original iterator's corresponding element in the second slot.Usage Example:
Definition at line 1300 of file CXXIter.h.
|
inlineconstexpr |
Draw elements from the given otherIterator
and use the returned elements as separators between the elements of this iterator.
This draws one element "into the future" of this iterator, in order to determine if another separator element from the given otherIterator
is required. The resulting iterator ends if either this iterator or the otherIterator
has no more elements to pull. The resulting iterator will always start and end on an element from this iterator.
otherIterator | Iterator whose elements will be inserted as separator elements between the elements of this iterator. |
otherIterator's
elements as separators between this iterator's elements.Usage Example:
|
inlineconstexpr |
Consumer that yields the last element of this iterator.
Usage Example:
Definition at line 1204 of file CXXIter.h.
|
inlineconstexpr |
Creates an iterator that uses the given mapFn
to map each element from this iterator to elements of the new iterator.
This pulls a new value from this iterator, maps it to a new value (can have a completely new type) using the given mapFn
and then yields that as new item for thew newly created iterator.
mapFn | Function that maps items from this iterator to a new value. |
mapFn
.Usage Example:
|
inlineconstexpr |
Consumer that yields the largest element from this iterator.
Usage Example:
Definition at line 973 of file CXXIter.h.
|
inlineconstexpr |
Consumer that yields the largest element from this iterator. Comparison of items is done using the comparison values returned by invoking the given compValueExtractFn
on each element.
compValueExtractFn | Function that, given an element from the input iterator as parameter returns the value by which the item should be compared to others. |
Usage Example:
Definition at line 1122 of file CXXIter.h.
|
inlineconstexpr |
Consumer that yields the index of the largest element within this iterator.
Usage Example:
Definition at line 996 of file CXXIter.h.
|
inlineconstexpr |
Consumer that yields the index of the largest element from this iterator. Comparison of items is done using the comparison values returned by invoking the given TCompValueExtractFn
on each element.
compValueExtractFn | Function that, given an element from the input iterator as parameter, returns the value by which the item should be compared to others. |
Usage Example:
Definition at line 1165 of file CXXIter.h.
|
inlineconstexpr |
Consumer that calculates the mean of all elements of this iterator.
The mean is calculated by first summing up all elements, and then dividing through the number of elements counted while summing.
sumStart | Optional starting point for the sum of all items. Normally uses default ctor of TResult . |
NORM | Type of the statistical normalization variant to use for the calculation. |
TResult | Type of the mean-calculation's result. This is also the type used for the sum of all elements. |
TCount | Type the element counter is converted into, before dividing the sum by. This can be necessary, if TResult is a complex object that only supports the division operator for e.g. double. |
Usage Example:
Definition at line 785 of file CXXIter.h.
|
inlineconstexpr |
Consumer that yields the smallest element from this iterator.
Usage Example:
Definition at line 924 of file CXXIter.h.
|
inlineconstexpr |
Consumer that yields the smallest element from this iterator. Comparison of items is done using the comparison values returned by invoking the given compValueExtractFn
on each element.
compValueExtractFn | Function that, given an element from the input iterator as parameter returns the value by which the item should be compared to others. |
Usage Example:
Definition at line 1032 of file CXXIter.h.
|
inlineconstexpr |
Consumer that yields the index of the smallest element within this iterator.
Usage Example:
Definition at line 947 of file CXXIter.h.
|
inlineconstexpr |
Consumer that yields the index of the smallest element from this iterator. Comparison of items is done using the comparison values returned by invoking the given compValueExtractFn
on each element.
compValueExtractFn | Function that, given an element from the input iterator as parameter, returns the value by which the item should be compared to others. |
Usage Example:
Definition at line 1074 of file CXXIter.h.
|
inlineconstexpr |
Allows to inspect and modify each item in-place, that passes through this iterator.
This can be used instead of a map() with the same type as input and output.
modifierFn | Function that is called for each item that passes through this iterator. |
modifierFn
.Usage Example:
|
inlineconstexpr |
Get the next element from this iterator (if any), wrapped in a CXXIter::IterValue<>.
next()
again after that is undefined behavior. Usage Example:
Definition at line 175 of file CXXIter.h.
|
inlineconstexpr |
Get the next element from the back of this iterator (if any), wrapped in a CXXIter::IterValue<>.
nextBack()
again after that is undefined behavior. Usage Example:
Definition at line 213 of file CXXIter.h.
|
inlineconstexpr |
Return the {n}-th element from this iterator (if available).
n | Index of the element to return from this iterator. |
{n}-th element from this iterator.Usage Example:
Definition at line 1229 of file CXXIter.h.
|
inlineconstexpr |
Constructs a new iterator that provides the elements of this iterator in reverse order.
Usage Example:
|
inlineconstexpr |
Get this iterator's exact size.
IterApi::filter
cause the remaining iterator to have an unknown exact size. Usage Example:
Definition at line 158 of file CXXIter.h.
|
inlineconstexpr |
|
inlineconstexpr |
Creates an iterator that skips the first cnt
elements from this iterator, before it yields the remaining items.
cnt | Amount of elements to skip from this iterator. |
cnt
elements from this iterator, before yielding the remaining items.Usage Example:
|
inlineconstexpr |
Creates an iterator that skips the first elements of this iterator, for which the given skipPredicate
returns true
.
The skipPredicate
is only called until it returned false
for the first time, after that its job is done.
skipPredicate | Predicate that determines the items whether an item at the beginning of this iterator should be skipped (true ). Should return false for the first item yielded from the resulted iterator. |
skipPredicate
returns false
for the first time. It then yields all remaining items of this iterator.Usage Example:
|
inlineconstexpr |
Creates a new iterator that takes the items from this iterator, and passes them on sorted.
ORDER | Decides the sort order of the resulting iterator. |
STABLE | If true , uses std::stable_sort internally, if false uses std::sort |
Usage Example:
|
inlineconstexpr |
Creates a new iterator that takes the items from this iterator, and passes them on sorted, using the supplied compareFn
.
compareFn | Compare function used for the sorting of items. |
compareFn
. STABLE | If true , uses std::stable_sort internally, if false uses std::sort |
Usage Example:
|
inlineconstexpr |
Creates a new iterator that takes the items from this iterator, and passes them on sorted.
In comparison to sort(), which either uses a custom comparator or the items themselves for the sort operation, this variant takes a sortValueExtractFn
, which extracts a value for each item in this iterator, that should be used for sorting comparisons.
ORDER | Decides the sort order of the resulting iterator. |
STABLE | If true , uses std::stable_sort internally, if false uses std::sort |
Usage Example:
|
inlineconstexpr |
Consumer that calculates the standard deviation of all elements of this iterator.
The standard deviation is calculated using
NORM | Type of the statistical normalization variant to use for the calculation. |
TResult | Type of the stddev-calculation's result. This is also the type used for the sum of all elements. |
TCount | Type the element counter is converted into, before dividing the sum and the squared sum by. This can be necessary, if TResult is a complex object that only supports the division operator for e.g. double. |
Usage Example:
|
inlineconstexpr |
Creates an iterator with the requested stepWidth
from this iterator.
A step width of 1
is a NO-OP, a step width of 2
means that every second element is skipped. The first element is always returned, irrespecting of the requested stepWidth
.
step | Step width with which elements from this iterator are yielded. |
stepWidth
Usage Example:
Definition at line 1871 of file CXXIter.h.
|
inline |
Consumer that concatenates the elements of this iterator to a large std::string
, where each element is separated by the specified separator
.
std::string
. If that is not the case, convert your items to std::string
s first, using a method like map()
. Usage Example:
Definition at line 746 of file CXXIter.h.
|
inlineconstexpr |
Consumer that calculates the sum of all elements from this iterator.
startValue | Starting value from which to start the sum. |
startValue
if this iterator had no elements.Usage Example:
Definition at line 708 of file CXXIter.h.
|
inlineconstexpr |
Creates an iterator that yields at most the first cnt
elements from this iterator.
cnt | Amount of elements to yield from this iterator. |
cnt
elements from this iterator.Usage Example:
|
inlineconstexpr |
Creates an iterator that yields the first elements of this iterator, for which the given takePredicate
returns true
.
The takePredicate
is only called until it returned false
for the first time, after that its job is done.
takePredicate | Predicate that determines the items returned by the newly constructed iterator. After this predicate yielded false for the first time, the new iterator ends. |
false
for the first time.Usage Example:
|
inlineconstexpr |
Constructs a new iterator that only contains every element of the input iterator only once.
This variant uses the input elements directly for the uniqueness-comparison. This requires the input elements to be hashable using std::hash
.
Usage Example:
Definition at line 1400 of file CXXIter.h.
|
inlineconstexpr |
Constructs a new iterator that only contains every element of the input iterator only once.
This variant checks whether the data returned by the given mapFn
when invoked with the input's item is unique. This requires the data returned by mapFn
to be hashable using std::hash
.
mapFn | Function that maps the input's element to data that should be used in the uniqueness-check. |
Usage Example:
|
inlineconstexpr |
Consumer that calculates the variance of all elements of this iterator.
The variance is calculated by incrementally calculating a sum and a squared sum of all elements. Then from there, the mean and then the variance are calculated.
NORM | Type of the statistical normalization variant to use for the calculation. |
TResult | Type of the variance-calculation's result. This is also the type used for the sum of all elements. |
TCount | Type the element counter is converted into, before dividing the sum and the squared sum by. This can be necessary, if TResult is a complex object that only supports the division operator for e.g. double. |
Usage Example:
Definition at line 839 of file CXXIter.h.
|
inlineconstexpr |
"Zips up" two CXXIter iterators into a single iterator over pairs from both iterators.
Constructs new iterator that iterates over std::pair<>
instances where values from this iterator are put in the first value, and values from the given otherIterator
become the second values. The resulting iterator is only as long as the shorter of both zipped iterators.
otherIterator | Second iterator zipped against this iterator. |
otherIterator
into a new iterator over std::pair<>
for both zipped iterator's values.Usage Example:
|
inlineconstexpr |
"Zips up" an arbitrary amount of CXXIter iterators into a single iterator over std::tuple<>
from both iterators.
Constructs new iterator that iterates over std::tuple<>
instances where values from this iterator are put in the first value, and values from the given otherIterators
are stored after that in order. The resulting iterator is only as long as the shortest of all iterators part of the zip.
otherIterators | Other iterators zipped against this iterator. |
otherIterators
into a new iterator over std::tuple<>
for all of the zipped iterator's values.Usage Example: