1#ifndef ORIGINAL_GENERATORS_H
2#define ORIGINAL_GENERATORS_H
26 template<
typename TYPE>
45 template<
typename TYPE,
typename SET = hashSet<TYPE>>
64 template<
typename TYPE,
template <
typename>
typename SERIAL =
vector>
86 template<
typename TYPE,
typename Callback>
107 template<
typename TYPE,
typename Callback>
128 template<
typename TYPE,
typename Callback>
152 template<
typename T,
typename U>
169 template<
typename TYPE>
188 template<
typename TYPE,
typename Callback>
207 template<
typename TYPE,
typename Callback>
226 template<
typename TYPE,
typename Callback>
245 template<
typename TYPE,
typename Callback>
269 template<
typename T, std::convertible_to<T> U>
290 template<
typename T, std::convertible_to<T> U>
311 template<
typename TYPE>
331 template<
typename TYPE>
351 template<
typename TYPE,
typename Callback>
371 template<
typename TYPE,
typename Callback>
395 template<
typename Callback>
403 template<
typename Generator>
406 template<
typename TYPE,
typename F>
409 template<
typename T,
typename U>
412 template<
typename T,
typename U>
474 template<
typename TYPE,
typename F>
522 template<
typename =
void>
532 template<
typename =
void>
542 template<
typename =
void>
554 template<
typename T,
typename U>
565 template<
typename T,
typename U>
585 template<
typename =
void>
649template <
typename TYPE>
654 for (
auto elem : gen)
661template<
typename TYPE,
typename SET>
666 for (
auto elem : gen)
673template <
typename TYPE,
template <
typename>
class SERIAL>
678 for (
auto elem : gen)
685template <
typename TYPE,
typename Callback>
690 co_yield c(std::forward<TYPE>(
elem));
694template <
typename TYPE,
typename Callback>
698 for (
auto elem : gen)
700 if (c(std::forward<TYPE>(elem)))
707template <
typename TYPE,
typename Callback>
711 for (
auto elem : gen)
713 if (c(std::forward<TYPE>(elem)))
721template <
typename T,
typename U>
723original::zip(coroutine::generator<T> gen1, coroutine::generator<U> gen2)
725 auto elem1 = gen1.
next();
726 auto elem2 = gen2.next();
727 while (elem1 && elem2)
729 co_yield {std::move(*elem1), std::move(*elem2)};
730 elem1 = std::move(gen1.next());
731 elem2 = std::move(gen2.next());
735template <
typename TYPE>
739 while (
auto val = gen.next())
746template <
typename TYPE,
typename Callback>
750 while (
auto val = gen.next())
752 if (c(std::forward<TYPE>(*val)))
758template <
typename TYPE,
typename Callback>
761 while (
auto val =
gen.next())
763 if (!c(std::forward<TYPE>(*
val)))
769template <
typename TYPE,
typename Callback>
772 while (
auto val =
gen.next())
774 if (c(std::forward<TYPE>(*
val)))
780template <
typename TYPE,
typename Callback>
783 while (
auto val =
gen.next())
785 if (c(std::forward<TYPE>(*
val)))
791template<
typename T, std::convertible_to<T> U>
793original::join(coroutine::generator<T> gen1, coroutine::generator<U> gen2)
795 for (
auto elem : gen1)
799 for (
auto elem : gen2)
801 co_yield static_cast<T
>(elem);
805template <
typename T, std::convertible_to<T> U>
809 for (
auto [elem1, elem2] : gen)
812 co_yield static_cast<T
>(elem2);
816template <
typename TYPE>
821 for (
auto elem : gen)
832template <
typename TYPE>
837 for (
auto elem : gen)
848template <
typename TYPE,
typename Callback>
852 for (
auto elem : gen)
854 if (c(std::forward<TYPE>(elem))){
862template <
typename TYPE,
typename Callback>
867 if (c(std::forward<TYPE>(
elem)))
875template <
typename Callback>
878template <
typename Callback>
879template <
typename Generator>
882 return this->c_(std::forward<Generator>(gen));
885template <
typename TYPE,
typename F>
888 return p(std::move(
gen));
939template <
typename T,
typename U>
947template<
typename T,
typename U>
975 return count(std::move(
gen), std::move(c));
983 return all(std::move(
gen), std::move(c));
991 return none(std::move(
gen), std::move(c));
999 return any(std::move(
gen), std::move(c));
1015 return find(std::move(
gen), std::move(c));
Lazy sequence generator using C++20 coroutines.
Definition coroutines.h:57
alternative< TYPE > next()
Advances generator and gets next value.
Definition coroutines.h:408
Pipe adapter for generator operations to enable fluent chaining.
Definition generators.h:396
friend auto enumerate()
Creates an enumerate pipe operation.
friend auto skip(u_integer n)
Creates a skip pipe operation.
friend auto all(F &&f)
Creates an all-match pipe operation.
friend auto take(u_integer n)
Creates a take pipe operation.
friend auto any(F &&f)
Creates an any-match pipe operation.
friend auto none(F &&f)
Creates a none-match pipe operation.
friend auto flatten()
Creates a flatten pipe operation.
friend auto filters(F &&f)
Creates a filter pipe operation.
friend auto find(F &&f)
Creates an element-finding pipe operation.
friend auto position(F &&f)
Creates a position-finding pipe operation.
friend auto count()
Creates a count pipe operation.
friend auto count(F &&f)
Creates a conditional count pipe operation.
friend auto operator|(coroutine::generator< TYPE > gen, genPipe< F > p)
Pipe operator for generator operations.
friend auto extract(F &&f)
Creates an extract pipe operation.
friend auto transforms(F &&f)
Creates a transform pipe operation.
A placeholder type representing the absence of a value.
Definition types.h:33
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Dynamic array container with amortized constant time operations.
Definition vector.h:43
Checks derivation or type identity using std::derived_from.
Definition types.h:472
C++20 coroutine support with generator pattern implementation.
Generic pair container implementation.
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
Main namespace for the project Original.
Definition algorithms.h:21
coroutine::generator< TYPE > skip(coroutine::generator< TYPE > gen, u_integer n)
Skips the first n elements of a generator.
bool all(coroutine::generator< TYPE > gen, Callback &&c)
Checks if all elements satisfy a predicate.
Definition generators.h:759
coroutine::generator< TYPE > take(coroutine::generator< TYPE > gen, u_integer n)
Takes the first n elements from a generator.
auto zipWith(coroutine::generator< U > gen2)
Creates a zipWith pipe operation.
Definition generators.h:956
TYPE find(coroutine::generator< TYPE > gen, Callback &&c)
Finds the first element satisfying a predicate.
Definition generators.h:863
coroutine::generator< T > join(coroutine::generator< T > gen1, coroutine::generator< U > gen2)
Joins two generators of compatible types.
coroutine::generator< TYPE > filters(coroutine::generator< TYPE > gen, Callback &&c)
Filters generator elements based on a predicate.
coroutine::generator< TYPE > extract(coroutine::generator< TYPE > gen, Callback &&c)
Extracts elements that do not satisfy a predicate.
u_integer position(coroutine::generator< TYPE > gen, Callback &&c)
Finds the position of the first element satisfying a predicate.
auto enumerate()
Creates an enumerate pipe operation.
Definition generators.h:916
bitSet< ALLOC_ > operator|(const bitSet< ALLOC_ > &lbs, const bitSet< ALLOC_ > &rbs)
Bitwise OR operator for two bitSets.
SET collect(coroutine::generator< TYPE > gen)
Collects generator elements into a set.
auto transforms(coroutine::generator< TYPE > gen, Callback &&c) -> coroutine::generator< std::invoke_result_t< Callback, TYPE > >
Transforms generator elements using a callable.
Definition generators.h:686
coroutine::generator< couple< T, U > > zip(coroutine::generator< T > gen1, coroutine::generator< U > gen2)
Zips two generators into pairs.
auto count()
Creates a count pipe operation.
Definition generators.h:964
bool any(coroutine::generator< TYPE > gen, Callback &&c)
Checks if any element satisfies a predicate.
Definition generators.h:781
auto flatten()
Creates a flatten pipe operation.
Definition generators.h:948
SERIAL< TYPE > list(coroutine::generator< TYPE > gen)
Collects generator elements into a list container.
Standard namespace extensions for original::alternative.
Definition allocator.h:351
Implementation of set containers with different underlying data structures.