10#include <unordered_map>
14#include "src/Common.h"
15#include "src/Generator.h"
16#include "src/sources/Concepts.h"
17#include "src/sources/ContainerSources.h"
18#include "src/sources/GeneratorSources.h"
19#include "src/Collector.h"
20#include "src/op/Alternater.h"
21#include "src/op/Caster.h"
22#include "src/op/Chainer.h"
23#include "src/op/Chunked.h"
24#include "src/op/ChunkedExact.h"
25#include "src/op/Filter.h"
26#include "src/op/FilterMap.h"
27#include "src/op/FlagLast.h"
28#include "src/op/FlatMap.h"
29#include "src/op/GenerateFrom.h"
30#include "src/op/GroupBy.h"
31#include "src/op/InplaceModifier.h"
32#include "src/op/Intersperser.h"
33#include "src/op/Map.h"
34#include "src/op/Reverse.h"
35#include "src/op/SkipN.h"
36#include "src/op/SkipWhile.h"
37#include "src/op/Sorter.h"
38#include "src/op/TakeN.h"
39#include "src/op/TakeWhile.h"
40#include "src/op/Unique.h"
41#include "src/op/Zipper.h"
42#include "src/Helpers.h"
57template<CXXIterIterator TSelf>
74 constexpr TSelf* self() {
return static_cast<TSelf*
>(
this); }
75 constexpr const TSelf* self()
const {
return static_cast<const TSelf*
>(
this); }
76 static constexpr bool IS_REFERENCE = std::is_lvalue_reference_v<Item>;
89 iterator(TSelf& self) : self(self) {}
97 element = self.next();
102 Item& operator*() {
return element.
value(); }
104 bool operator!=(
const iterator& o) {
158 constexpr size_t size() const requires CXXIterExactSizeIterator<TSelf> {
240 template<
typename TUseFn>
244 if(!item.has_value()) [[unlikely]] {
return; }
245 useFn(std::forward<Item>( item.value() ));
272 template<
template <
typename...>
typename TTargetContainer,
typename... TTargetContainerArgs>
274 return Collector<TSelf, TTargetContainer, TTargetContainerArgs...>::template collect<Item, ItemOwned>(*self());
305 template<
typename TTargetContainer>
307 TTargetContainer container;
328 template<
typename TTargetContainer>
330 IntoCollector<TSelf, TTargetContainer>::collectInto(*self(), container);
352 template<
typename TResult, std::invocable<TResult&, Item&&> FoldFn>
353 constexpr TResult
fold(TResult startValue, FoldFn foldFn) {
354 TResult result = startValue;
355 forEach([&result, &foldFn](
Item&& item) { foldFn(result, std::forward<Item>(item)); });
394 template<std::invocable<const ItemOwned&> TPredicateFn>
395 requires std::same_as<std::invoke_result_t<TPredicateFn, const ItemOwned&>,
bool>
396 constexpr bool all(TPredicateFn predicateFn) {
397 return !
skipWhile(predicateFn).next().has_value();
432 {
static_cast<bool>(item)};
434 return all([](
const auto& item) ->
bool {
return item; });
471 template<std::invocable<const ItemOwned&> TPredicateFn>
472 constexpr bool any(TPredicateFn predicateFn) {
473 return filter(predicateFn).next().has_value();
508 {
static_cast<bool>(item)};
510 return any([](
const auto& item) ->
bool {
return item; });
534 {searchItem == item} -> std::same_as<bool>;
537 return (searchItem == item);
564 template<std::invocable<const ItemOwned&> TFindFn>
565 constexpr std::optional<size_t>
findIdx(TFindFn findFn) {
569 if(!item.has_value()) [[unlikely]] {
return {}; }
570 if(findFn(item.value())) [[unlikely]] {
return idx; }
601 template<std::invocable<const ItemOwned&> TFindFn>
603 return filter(findFn).next();
622 return fold((
size_t)0, [](
size_t& cnt,
auto&&) { cnt += 1; });
641 template<std::invocable<const ItemOwned&> TPredicateFn>
642 constexpr size_t count(TPredicateFn predicateFn) {
643 return fold((
size_t)0, [&predicateFn](
size_t& cnt,
auto&& item) {
644 if(predicateFn(item)) { cnt += 1; }
667 return fold((
size_t)0, [&countItem](
size_t& cnt,
auto&& item) {
668 if(item == countItem) { cnt += 1; }
706 template<
typename TResult = ItemOwned>
707 requires requires(TResult res,
Item item) { { res += item }; }
708 constexpr TResult
sum(TResult startValue = TResult()) {
709 return fold(startValue, [](TResult& res,
Item&& item) { res += item; });
746 std::string
stringJoin(
const std::string& separator)
requires std::is_same_v<ItemOwned, std::string> {
748 forEach([&result, &separator](
const std::string& item) {
749 if(result.size() > 0) [[likely]] { result += separator + item; }
750 else [[unlikely]] { result = item; }
784 template<StatisticNormalization NORM = StatisticNormalization::N,
typename TResult = ItemOwned,
typename TCount = ItemOwned>
785 constexpr std::optional<TResult>
mean(TResult sumStart = TResult()) {
787 TResult result =
fold(sumStart, [&cnt](TResult& res,
Item&& item) {
793 return result /
static_cast<TCount
>(cnt);
795 return result /
static_cast<TCount
>(cnt - 1);
838 template<StatisticNormalization NORM = StatisticNormalization::N,
typename TResult = ItemOwned,
typename TCount = ItemOwned>
840 TResult sumSquare = TResult();
841 TResult
sum = TResult();
845 sumSquare += (item * item);
850 TResult E1 = (sumSquare /
static_cast<TCount
>(cnt));
851 TResult E2 = (
sum /
static_cast<TCount
>(cnt));
852 return E1 - (E2 * E2);
854 TResult E1 = (
sum *
sum /
static_cast<TCount
>(cnt));
855 return (sumSquare - E1) /
static_cast<TCount
>(cnt - 1);
895 template<StatisticNormalization NORM = StatisticNormalization::N,
typename TResult = ItemOwned,
typename TCount = ItemOwned>
896 constexpr std::optional<TResult>
stddev() {
897 std::optional<TResult> result = variance<NORM, TResult, TCount>();
898 if(result.has_value()) {
return std::sqrt(result.value()); }
925 return minBy([](
auto&& item) {
return item; });
947 constexpr std::optional<size_t>
minIdx() {
948 return minIdxBy([](
auto&& item) {
return item; });
974 return maxBy([](
auto&& item) {
return item; });
996 constexpr std::optional<size_t>
maxIdx() {
997 return maxIdxBy([](
auto&& item) {
return item; });
1027 template<
typename TCompValueExtractFn>
1028 requires requires(
const std::invoke_result_t<TCompValueExtractFn, Item&&>& a, std::remove_cvref_t<
decltype(a)> ownedA) {
1030 { ownedA = ownedA };
1035 auto resultValue = compValueExtractFn(std::forward<Item>(result.
value()));
1036 forEach([&result, &resultValue, &compValueExtractFn](
Item&& item) {
1037 auto itemValue = compValueExtractFn(std::forward<Item>(item));
1038 if(itemValue < resultValue) {
1040 resultValue = itemValue;
1070 template<
typename TCompValueExtractFn>
1071 requires requires(
const std::invoke_result_t<TCompValueExtractFn, Item&&>& a) {
1074 constexpr std::optional<size_t>
minIdxBy(TCompValueExtractFn compValueExtractFn) {
1077 size_t iterationIdx = 1,
minIdx = 0;
1078 auto minValue = compValueExtractFn(std::forward<Item>(tmp.
value()));
1079 forEach([iterationIdx, &
minIdx, &minValue, &compValueExtractFn](
Item&& item)
mutable {
1080 auto itemValue = compValueExtractFn(std::forward<Item>(item));
1081 if(itemValue < minValue) {
1082 minValue = itemValue;
1117 template<
typename TMaxValueExtractFn>
1118 requires requires(
const std::invoke_result_t<TMaxValueExtractFn, Item&&>& a, std::remove_cvref_t<
decltype(a)> ownedA) {
1120 { ownedA = ownedA };
1125 auto resultValue = compValueExtractFn(std::forward<Item>(result.
value()));
1126 forEach([&result, &resultValue, &compValueExtractFn](
Item&& item) {
1127 auto itemValue = compValueExtractFn(std::forward<Item>(item));
1128 if(itemValue > resultValue) {
1130 resultValue = itemValue;
1160 template<
typename TMaxValueExtractFn>
1161 requires requires(
const std::invoke_result_t<TMaxValueExtractFn, Item&&>& a, std::remove_cvref_t<
decltype(a)> ownedA) {
1163 { ownedA = ownedA };
1165 constexpr std::optional<size_t>
maxIdxBy(TMaxValueExtractFn compValueExtractFn) {
1168 size_t iterationIdx = 1,
maxIdx = 0;
1169 auto maxValue = compValueExtractFn(std::forward<Item>(tmp.
value()));
1170 forEach([iterationIdx, &
maxIdx, &maxValue, &compValueExtractFn](
Item&& item)
mutable {
1171 auto itemValue = compValueExtractFn(std::forward<Item>(item));
1172 if(itemValue > maxValue) {
1173 maxValue = itemValue;
1230 return skip(n).next();
1257 template<
typename TItemOutput>
1258 constexpr op::Caster<TSelf, TItemOutput>
cast() {
1259 return op::Caster<TSelf, TItemOutput>(std::move(*self()));
1302 return map([idx](
Item&& item)
mutable -> std::pair<size_t, Item> {
1303 return std::pair<size_t, Item>(idx++, std::forward<Item>(item));
1334 return op::FlagLast<TSelf>(std::move(*self()));
1352 template<std::invocable<const ItemOwned&> TFilterFn>
1353 constexpr op::Filter<TSelf, TFilterFn>
filter(TFilterFn filterFn) {
1354 return op::Filter<TSelf, TFilterFn>(std::move(*self()), filterFn);
1376 template<std::invocable<const ItemOwned&> TMapFn>
1377 requires util::is_hashable<std::invoke_result_t<TMapFn, const ItemOwned&>>
1378 constexpr op::Unique<TSelf, TMapFn>
unique(TMapFn mapFn) {
1379 return op::Unique<TSelf, TMapFn>(std::move(*self()), mapFn);
1401 return unique([](
const auto& item) {
return item; });
1422 return op::Reverse<TSelf>(std::move(*self()));
1453 template<const
size_t CHUNK_SIZE>
1454 constexpr op::Chunked<TSelf, CHUNK_SIZE>
chunked() {
1455 return op::Chunked<TSelf, CHUNK_SIZE>(std::move(*self()));
1561 template<const
size_t CHUNK_SIZE, const
size_t STEP_SIZE = CHUNK_SIZE>
1563 return op::ChunkedExact<TSelf, CHUNK_SIZE, STEP_SIZE>(std::move(*self()));
1584 template<std::invocable<Item&&> TMapFn>
1585 constexpr auto map(TMapFn mapFn) {
1586 using TMapFnResult = std::invoke_result_t<TMapFn, Item&&>;
1587 return op::Map<TSelf, TMapFn, TMapFnResult>(std::move(*self()), mapFn);
1610 template<std::invocable<Item&&> TFlatMapFn>
1612 using TFlatMapFnResult = std::invoke_result_t<TFlatMapFn, Item&&>;
1613 return op::FlatMap<TSelf, TFlatMapFn, TFlatMapFnResult>(std::move(*self()), mapFn);
1616#ifdef CXXITER_HAS_COROUTINE
1688 template<GeneratorFromFunction<Item> TGeneratorFn>
1690 using TGeneratorFnResult = std::invoke_result_t<TGeneratorFn, Item>;
1691 return op::GenerateFrom<TSelf, TGeneratorFn, TGeneratorFnResult>(std::move(*self()), generatorFn);
1731 template<std::invocable<Item&> TModifierFn>
1732 constexpr op::InplaceModifier<TSelf, TModifierFn>
modify(TModifierFn modifierFn) {
1733 return op::InplaceModifier<TSelf, TModifierFn>(std::move(*self()), modifierFn);
1755 template<std::invocable<ItemOwned&&> TFilterMapFn>
1756 requires util::is_optional<std::invoke_result_t<TFilterMapFn, ItemOwned&&>>
1758 using TFilterMapFnResult =
typename std::invoke_result_t<TFilterMapFn, ItemOwned&&>::value_type;
1759 return op::FilterMap<TSelf, TFilterMapFn, TFilterMapFnResult>(std::move(*self()), filterMapFn);
1776 constexpr op::SkipN<TSelf>
skip(
size_t cnt) {
1777 return op::SkipN<TSelf>(std::move(*self()), cnt);
1800 template<std::invocable<const Item&> TSkipPredicate>
1801 constexpr op::SkipWhile<TSelf, TSkipPredicate>
skipWhile(TSkipPredicate skipPredicate) {
1802 return op::SkipWhile<TSelf, TSkipPredicate>(std::move(*self()), skipPredicate);
1818 constexpr op::TakeN<TSelf>
take(
size_t cnt) {
1819 return op::TakeN<TSelf>(std::move(*self()), cnt);
1840 template<std::invocable<const Item&> TTakePredicate>
1841 requires std::is_same_v<std::invoke_result_t<TTakePredicate, const Item&>,
bool>
1843 return op::TakeWhile<TSelf, TTakePredicate>(std::move(*self()), takePredicate);
1875 return (idx++ % stepWidth) == 0;
1897 template<
typename TOtherIterator>
1898 constexpr op::Zipper<TSelf, std::pair, TOtherIterator>
zip(TOtherIterator&& otherIterator) {
1899 return op::Zipper<TSelf, std::pair, TOtherIterator>(std::move(*self()), std::forward<TOtherIterator>(otherIterator));
1922 template<
typename... TOtherIterators>
1923 requires (CXXIterIterator<TOtherIterators> && ...)
1924 && (!std::disjunction_v< std::is_reference<typename trait::Iterator<TOtherIterators>::Item>... > && !IS_REFERENCE)
1925 constexpr op::Zipper<TSelf, std::tuple, TOtherIterators...>
zipTuple(TOtherIterators&&... otherIterators) {
1926 return op::Zipper<TSelf, std::tuple, TOtherIterators...>(std::move(*self()), std::forward<TOtherIterators>(otherIterators)...);
1946 template<
typename TOtherIterator>
1947 requires std::is_same_v<Item, typename TOtherIterator::Item>
1948 constexpr op::Chainer<TSelf, TOtherIterator>
chain(TOtherIterator&& otherIterator) {
1949 return op::Chainer<TSelf, TOtherIterator>(std::move(*self()), std::forward<TOtherIterator>(otherIterator));
1971 template<
typename... TOtherIterators>
1972 requires (CXXIterIterator<TOtherIterators> && ...)
1973 && (util::are_same_v<
Item,
typename TOtherIterators::Item...>)
1974 constexpr op::Alternater<TSelf, TOtherIterators...>
alternate(TOtherIterators&&... otherIterators) {
1975 return op::Alternater<TSelf, TOtherIterators...>(std::move(*self()), std::forward<TOtherIterators>(otherIterators)...);
2016 template<
typename TOtherIterator>
2017 requires (std::is_same_v<Item, typename TOtherIterator::Item>)
2018 constexpr op::Intersperser<TSelf, TOtherIterator>
intersperse(TOtherIterator&& otherIterator) {
2019 return op::Intersperser<TSelf, TOtherIterator>(std::move(*self()), std::forward<TOtherIterator>(otherIterator));
2048 template<std::invocable<const Item&> TGroupIdentifierFn>
2049 requires util::is_hashable<std::invoke_result_t<TGroupIdentifierFn, const Item&>>
2050 constexpr auto groupBy(TGroupIdentifierFn groupIdentFn) {
2051 using TGroupIdent = std::remove_cvref_t<std::invoke_result_t<TGroupIdentifierFn, const ItemOwned&>>;
2052 return op::GroupBy<TSelf, TGroupIdentifierFn, TGroupIdent>(std::move(*self()), groupIdentFn);
2084 template<
bool STABLE, std::invocable<const ItemOwned&, const ItemOwned&> TCompareFn>
2085 constexpr auto sort(TCompareFn compareFn) {
2086 return op::Sorter<TSelf, TCompareFn, STABLE>(std::move(*self()), compareFn);
2114 template<SortOrder ORDER = SortOrder::ASCENDING,
bool STABLE = false>
2115 requires requires(
const ItemOwned& a) { { a < a }; { a > a }; }
2118 if constexpr(ORDER == SortOrder::ASCENDING) {
2153 template<SortOrder ORDER = SortOrder::ASCENDING,
bool STABLE = false, std::invocable<const ItemOwned&> TSortValueExtractFn>
2154 requires requires(
const std::invoke_result_t<TSortValueExtractFn, const ItemOwned&>& a) {
2155 { a < a }; { a > a };
2157 constexpr auto sortBy(TSortValueExtractFn sortValueExtractFn) {
2159 if constexpr(ORDER == SortOrder::ASCENDING) {
2160 return (sortValueExtractFn(a) < sortValueExtractFn(b));
2162 return (sortValueExtractFn(a) > sortValueExtractFn(b));
2186 template<
typename TContainer>
2187 requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
2188 constexpr SrcMov<std::remove_cvref_t<TContainer>>
from(TContainer&& container) {
2199 template<
typename TContainer>
2200 requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
2201 constexpr SrcRef<std::remove_cvref_t<TContainer>>
from(TContainer& container) {
2212 template<
typename TContainer>
2213 requires (!std::is_reference_v<TContainer> && !util::is_const_reference_v<TContainer> && concepts::SourceContainer<TContainer>)
2214 constexpr SrcCRef<std::remove_cvref_t<TContainer>>
from(
const TContainer& container) {
2235 template<
typename TItem>
2236 constexpr Empty<TItem>
empty() {
return Empty<TItem>(); }
2259 template<std::invocable<> TGeneratorFn>
2260 requires util::is_optional<std::invoke_result_t<TGeneratorFn>>
2261 constexpr auto fromFn(TGeneratorFn generatorFn) {
2262 using TGeneratorFnResult =
typename std::invoke_result_t<TGeneratorFn>::value_type;
2263 return FunctionGenerator<TGeneratorFnResult, TGeneratorFn>(generatorFn);
2266 #ifdef CXXITER_HAS_COROUTINE
2288 template<GeneratorFunction TGeneratorFn>
2290 using TGenerator =
typename std::invoke_result_t<TGeneratorFn>;
2291 TGenerator generator = generatorFn();
2292 return CoroutineGenerator<TGenerator>(std::forward<TGenerator>(generator));
2312 template<
typename TItem>
2313 constexpr Repeater<TItem>
repeat(
const TItem& item, std::optional<size_t> cnt = {}) {
2314 return Repeater<TItem>(item, cnt);
2340 template<
typename TValue>
2341 constexpr Range<TValue>
range(TValue
from, TValue to, TValue step = 1) {
2342 return Range<TValue>(
from, to, step);
C++ iterator implementation for a CXXIter chain.
Public Iterator API surface.
typename Iterator::Item Item
Type of the elements of this iterator. (Can be references)
constexpr auto collect()
Consumer that collects all elements from this iterator in a new container of type TTargetContainer.
constexpr void collectInto(TTargetContainer &container)
Consumer that collects all elements from this iterator into the given container.
constexpr op::Alternater< TSelf, TOtherIterators... > alternate(TOtherIterators &&... otherIterators)
Alternating the elements of this iterator with the ones from the other given iterator(s).
constexpr auto generateFrom(TGeneratorFn generatorFn)
Creates a new iterator containing the items that the given generator produces for each element in thi...
constexpr std::optional< size_t > maxIdx()
Consumer that yields the index of the largest element within this iterator.
constexpr IterValue< Item > minBy(TCompValueExtractFn compValueExtractFn)
Consumer that yields the smallest element from this iterator. Comparison of items is done using the c...
constexpr void advanceBy(size_t n)
Advance the iterator by n elements.
constexpr auto takeWhile(TTakePredicate takePredicate)
Creates an iterator that yields the first elements of this iterator, for which the given takePredicat...
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,...
constexpr auto indexed()
Constructs a new iterator that tags each element of this iterator with the corresponding index,...
constexpr op::Unique< TSelf, TMapFn > unique(TMapFn mapFn)
Constructs a new iterator that only contains every element of the input iterator only once.
constexpr op::Reverse< TSelf > reverse()
Constructs a new iterator that provides the elements of this iterator in reverse order.
constexpr auto stepBy(size_t stepWidth)
Creates an iterator with the requested stepWidth from this iterator.
constexpr IterValue< Item > nth(size_t n)
Return the {n}-th element from this iterator (if available).
constexpr op::Caster< TSelf, TItemOutput > cast()
Constructs a new iterator that casts the elements of this iterator to the type requested by TItemOutp...
constexpr IterValue< Item > max()
Consumer that yields the largest element from this iterator.
constexpr IterValue< Item > nextBack()
Get the next element from the back of this iterator (if any), wrapped in a CXXIter::IterValue<>.
constexpr auto unique()
Constructs a new iterator that only contains every element of the input iterator only once.
constexpr size_t size() const
Get this iterator's exact size.
constexpr auto map(TMapFn mapFn)
Creates an iterator that uses the given mapFn to map each element from this iterator to elements of t...
constexpr IterValue< Item > last()
Consumer that yields the last element of this iterator.
constexpr auto filterMap(TFilterMapFn filterMapFn)
Creates a new iterator that filters and maps items from this iterator.
constexpr op::FlagLast< TSelf > flagLast()
Constructs a new iterator that tags each element with a boolean value specifying whether the element ...
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...
constexpr IterValue< Item > maxBy(TMaxValueExtractFn compValueExtractFn)
Consumer that yields the largest element from this iterator. Comparison of items is done using the co...
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...
std::remove_cvref_t< Item > ItemOwned
Owned Type of the elements of this iterator. (References removed).
constexpr TResult sum(TResult startValue=TResult())
Consumer that calculates the sum of all elements from this iterator.
constexpr op::TakeN< TSelf > take(size_t cnt)
Creates an iterator that yields at most the first cnt elements from this iterator.
constexpr auto groupBy(TGroupIdentifierFn groupIdentFn)
Groups the elements of this iterator according to the values returned by the given groupidentFn.
constexpr op::InplaceModifier< TSelf, TModifierFn > modify(TModifierFn modifierFn)
Allows to inspect and modify each item in-place, that passes through this iterator.
constexpr size_t count(TPredicateFn predicateFn)
Consumer that counts the elements in this iterator, for which the given predicateFn returns true.
constexpr void forEach(TUseFn useFn)
Consumer that calls the given function useFn for each of the elements in this iterator.
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,...
constexpr op::Intersperser< TSelf, TOtherIterator > intersperse(TOtherIterator &&otherIterator)
Draw elements from the given otherIterator and use the returned elements as separators between the el...
constexpr std::optional< size_t > minIdxBy(TCompValueExtractFn compValueExtractFn)
Consumer that yields the index of the smallest element from this iterator. Comparison of items is don...
constexpr std::optional< TResult > mean(TResult sumStart=TResult())
Consumer that calculates the mean of all elements of this iterator.
constexpr std::optional< size_t > minIdx()
Consumer that yields the index of the smallest element within this iterator.
constexpr SizeHint sizeHint() const
Get the bounds on the remaining length of this iterator, estimated from the source and all of the cha...
constexpr std::optional< TResult > variance()
Consumer that calculates the variance of all elements of this iterator.
constexpr bool any()
Tests if any of the elements of this iterator yield the value true when casted to bool.
constexpr auto copied()
Constructs a new iterator that copies the elements of this iterator.
constexpr op::Chunked< TSelf, CHUNK_SIZE > chunked()
Create new iterator that collects elements from this iterator in chunks of size up to CHUNK_SIZE,...
constexpr size_t count(const ItemOwned &countItem)
Consumer that counts the occurences of countItem within this iterator.
constexpr IterValue< Item > find(TFindFn findFn)
Searches for an element of this iterator, that satisfies the given findFn predicate.
constexpr auto flatMap()
Creates an iterator that flattens the iterable elements of this iterator.
constexpr auto sortBy(TSortValueExtractFn sortValueExtractFn)
Creates a new iterator that takes the items from this iterator, and passes them on sorted.
iterator begin()
begin() method, part of C++'s iterator interface
constexpr op::SkipWhile< TSelf, TSkipPredicate > skipWhile(TSkipPredicate skipPredicate)
Creates an iterator that skips the first elements of this iterator, for which the given skipPredicate...
constexpr bool any(TPredicateFn predicateFn)
Tests if any of the elements of this iterator match the given predicateFn.
constexpr op::SkipN< TSelf > skip(size_t cnt)
Creates an iterator that skips the first cnt elements from this iterator, before it yields the remain...
std::string stringJoin(const std::string &separator)
Consumer that concatenates the elements of this iterator to a large std::string , where each element ...
iterator end()
end() method, part of C++'s iterator interface
constexpr bool all(TPredicateFn predicateFn)
Tests if all elements of this iterator match the given predicateFn.
constexpr TTargetContainer collect()
Consumer that collects all elements from this iterator in a new container of type TTargetContainer.
constexpr size_t count()
Consumer that counts the elements in this iterator.
constexpr op::Zipper< TSelf, std::pair, TOtherIterator > zip(TOtherIterator &&otherIterator)
"Zips up" two CXXIter iterators into a single iterator over pairs from both iterators.
constexpr bool all()
Tests if all elements of this iterator yield the value true when casted to bool.
constexpr IterValue< Item > min()
Consumer that yields the smallest element from this iterator.
constexpr auto flatMap(TFlatMapFn mapFn)
Creates an iterator that works like map(), but flattens nested containers.
constexpr auto sort()
Creates a new iterator that takes the items from this iterator, and passes them on sorted.
constexpr op::Chainer< TSelf, TOtherIterator > chain(TOtherIterator &&otherIterator)
Chains this iterator with the given otherIterator, resulting in a new iterator that first yields the ...
constexpr std::optional< TResult > stddev()
Consumer that calculates the standard deviation of all elements of this iterator.
constexpr IterValue< Item > next()
Get the next element from this iterator (if any), wrapped in a CXXIter::IterValue<>.
constexpr auto sort(TCompareFn compareFn)
Creates a new iterator that takes the items from this iterator, and passes them on sorted,...
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 ...
constexpr op::Filter< TSelf, TFilterFn > filter(TFilterFn filterFn)
Constructs a new iterator that only contains the elements from this iterator, for which the given fil...
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...
Container that is used to pass elements through CXXIter's iterator pipelines.
constexpr bool has_value() const noexcept
Get whether this optional IteratorValue contains a value.
constexpr const TValueDeref & value() const
Get the contained value (if any).
CXXIter iterator source that immutably borrows the input item source, and passes immutable references...
CXXIter iterator source that takes over the input item source, and moves its items through the elemen...
CXXIter iterator source that mutably borrows the input item source, and passes mutable references to ...
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...
auto generate(TGeneratorFn generatorFn)
Generator source that produces a new iterator over the elements produced by the given generatorFn - w...
constexpr Repeater< TItem > repeat(const TItem &item, std::optional< size_t > cnt={})
Construct a CXXIter iterator, by repeating the given item cnt times.
@ N
Use when the mean, variance, stddev is calculated with the COMPLETE population.
constexpr Empty< TItem > empty()
Constructs an empty iterator yielding no items.
constexpr SrcMov< std::remove_cvref_t< TContainer > > from(TContainer &&container)
Construct a CXXIter move source from the given container.
constexpr auto fromFn(TGeneratorFn generatorFn)
Generator source that takes a generatorFn, each invocation of which produces one element for the resu...
Structure holding the bounds of a CXXIter iterator's estimated length.
static constexpr IterValue< typename Iterator< T >::Item > nextBack(Self &self)=delete
Pull the next last element from the iterator pipeline previous to this pipeline-element.
static constexpr size_t size(const typename trait::Iterator< T >::Self &self)=delete
Get the iterator's exact number of elements.
Trait, that is used for the chaining and the operation of iterator pipelines.
static constexpr IterValue< Item > next(Self &self)=delete
Pull one element from the iterator pipeline previous to this pipeline-element.
void Item
Item-Type. This is the type of elements that can be pulled from this pipeline-element.
static constexpr SizeHint sizeHint(const Self &self)=delete
Get the bounds on the remaining length of the iterator pipeline until this pipeline-element,...
static constexpr size_t advanceBy(Self &self, size_t n)=delete
Advance the iterator by n elements.