Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::utils::FunctionalAdapterBase< Derived > Class Template Reference

CRTP base class providing common adapter operations. More...

#include <functional_adapters.hpp>

Public Member Functions

template<typename Pred>
constexpr auto Filter (Pred predicate) const noexcept(noexcept(FilterAdapter< Derived, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Chains another filter operation on top of this iterator.
template<typename Func>
constexpr auto Map (Func transform) const noexcept(noexcept(MapAdapter< Derived, Func >(GetDerived().begin(), GetDerived().end(), std::move(transform))))
 Transforms each element using the given function.
constexpr auto Take (size_t count) const noexcept(noexcept(TakeAdapter< Derived >(GetDerived().begin(), GetDerived().end(), count)))
 Limits the number of elements to at most count.
constexpr auto Skip (size_t count) const noexcept(noexcept(SkipAdapter< Derived >(GetDerived().begin(), GetDerived().end(), count)))
 Skips the first count elements.
template<typename Pred>
constexpr auto TakeWhile (Pred predicate) const noexcept(noexcept(TakeWhileAdapter< Derived, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Takes elements while a predicate is true.
template<typename Pred>
constexpr auto SkipWhile (Pred predicate) const noexcept(noexcept(SkipWhileAdapter< Derived, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Skips elements while a predicate is true.
constexpr auto Enumerate () const noexcept(noexcept(EnumerateAdapter< Derived >(GetDerived().begin(), GetDerived().end())))
 Adds an index to each element.
template<typename Func>
constexpr auto Inspect (Func inspector) const noexcept(noexcept(InspectAdapter< Derived, Func >(GetDerived().begin(), GetDerived().end(), std::move(inspector))))
 Observes each element without modifying it.
constexpr auto StepBy (size_t step) const noexcept(noexcept(StepByAdapter< Derived >(GetDerived().begin(), GetDerived().end(), step)))
 Takes every Nth element.
template<typename OtherIter>
constexpr auto Chain (OtherIter begin, OtherIter end) const noexcept(noexcept(ChainAdapter< Derived, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Chains another range after this one.
template<typename R>
constexpr auto Chain (R &range) const noexcept(noexcept(ChainAdapter< Derived, std::ranges::iterator_t< R > >(GetDerived().begin(), GetDerived().end(), range)))
 Chains another range after this one.
template<typename R>
constexpr auto Chain (const R &range) const noexcept(noexcept(ChainAdapter< Derived, std::ranges::iterator_t< const R > >(GetDerived().begin(), GetDerived().end(), range)))
 Chains another range after this one.
constexpr auto Reverse () const noexcept(noexcept(ReverseAdapter< Derived >(GetDerived().begin(), GetDerived().end())))
 Reverses the order of elements.
constexpr auto Slide (size_t window_size) const noexcept(noexcept(SlideAdapter< Derived >(GetDerived().begin(), GetDerived().end(), window_size)))
 Creates sliding windows over elements.
constexpr auto Stride (size_t stride) const noexcept(noexcept(StrideAdapter< Derived >(GetDerived().begin(), GetDerived().end(), stride)))
 Takes every Nth element with stride.
template<typename OtherIter>
constexpr auto Zip (OtherIter begin, OtherIter end) const noexcept(noexcept(ZipAdapter< Derived, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Zips another range with this one.
template<typename R>
constexpr auto Zip (R &range) const noexcept(noexcept(ZipAdapter< Derived, std::ranges::iterator_t< R > >(GetDerived().begin(), GetDerived().end(), range)))
 Zips another range with this one.
template<typename R>
constexpr auto Zip (const R &range) const noexcept(noexcept(ZipAdapter< Derived, std::ranges::iterator_t< const R > >(GetDerived().begin(), GetDerived().end(), range)))
 Zips another range with this one.
template<typename Action>
constexpr void ForEach (const Action &action) const
 Terminal operation: applies an action to each element.
template<typename T, typename Folder>
constexpr T Fold (T init, const Folder &folder) const
 Terminal operation: reduces elements to a single value using a folder function.
template<typename Pred>
constexpr auto Find (const Pred &predicate) const
 Terminal operation: finds the first element satisfying a predicate.
template<typename Pred>
constexpr size_t CountIf (const Pred &predicate) const
 Terminal operation: counts elements satisfying a predicate.
template<typename Pred>
constexpr auto Partition (const Pred &predicate) const
 Terminal operation: partitions elements into two groups based on a predicate.
template<typename Pred, typename Allocator>
requires std::same_as<typename Allocator::value_type, std::iter_value_t<Derived>>
constexpr auto PartitionWith (const Pred &predicate, Allocator allocator) const
 Terminal operation: partitions elements with a custom allocator.
template<typename KeyFunc>
constexpr auto MaxBy (const KeyFunc &key_func) const
 Terminal operation: finds the element with the maximum value according to a key function.
template<typename KeyFunc>
constexpr auto MinBy (const KeyFunc &key_func) const
 Terminal operation: finds the element with the minimum value according to a key function.
template<typename KeyFunc>
constexpr auto GroupBy (const KeyFunc &key_func) const
 Terminal operation: groups elements by a key function.
template<typename KeyFunc, typename MapAllocator, typename ValueAllocator>
constexpr auto GroupByWith (const KeyFunc &key_func, MapAllocator map_allocator, ValueAllocator value_allocator) const
 Terminal operation: groups elements by key with custom allocators.
constexpr auto Collect () const
 Terminal operation: collects all elements into a vector.
template<typename Allocator>
constexpr auto CollectWith (Allocator allocator={}) const
 Terminal operation: collects all elements into a vector with a custom allocator.
constexpr auto CollectWith (std::pmr::memory_resource *resource) const
 Terminal operation: collects all elements into a vector with a specific memory resource.
auto CollectWith (std::nullptr_t) const =delete
template<typename OutIt>
constexpr void Into (OutIt out) const
 Terminal operation: writes all elements into an output iterator.
template<typename Pred>
constexpr bool Any (const Pred &predicate) const
 Terminal operation: checks if any element satisfies a predicate.
template<typename Pred>
constexpr bool All (const Pred &predicate) const
 Terminal operation: checks if all elements satisfy a predicate.
template<typename Pred>
constexpr bool None (const Pred &predicate) const
 Terminal operation: checks if no elements satisfy a predicate.

Protected Member Functions

constexpr Derived & GetDerived () noexcept
 Gets reference to derived class instance.
constexpr const Derived & GetDerived () const noexcept
 Gets const reference to derived class instance.

Detailed Description

template<typename Derived>
class helios::utils::FunctionalAdapterBase< Derived >

CRTP base class providing common adapter operations.

Provides chaining methods (Filter, Map, Take, Skip, etc.) that can be used by any derived adapter class. Uses CRTP pattern to return the correct derived type.

Template Parameters
DerivedThe derived adapter class

Definition at line 3583 of file functional_adapters.hpp.

Member Function Documentation

◆ All()

template<typename Derived>
template<typename Pred>
bool helios::utils::FunctionalAdapterBase< Derived >::All ( const Pred & predicate) const
nodiscardconstexpr

Terminal operation: checks if all elements satisfy a predicate.

Template Parameters
PredPredicate type
Parameters
predicateFunction to test elements
Returns
True if all elements satisfy the predicate, false otherwise

Definition at line 4393 of file functional_adapters.hpp.

◆ Any()

template<typename Derived>
template<typename Pred>
bool helios::utils::FunctionalAdapterBase< Derived >::Any ( const Pred & predicate) const
nodiscardconstexpr

Terminal operation: checks if any element satisfies a predicate.

Template Parameters
PredPredicate type
Parameters
predicateFunction to test elements
Returns
True if any element satisfies the predicate, false otherwise

Definition at line 4375 of file functional_adapters.hpp.

◆ Chain() [1/3]

template<typename Derived>
template<typename R>
auto helios::utils::FunctionalAdapterBase< Derived >::Chain ( const R & range) const
inlinenodiscardconstexprnoexcept

Chains another range after this one.

Template Parameters
RRange type of the other adapter
Parameters
rangeThe other range to chain
Returns
ChainAdapter that yields elements from both ranges

Definition at line 3743 of file functional_adapters.hpp.

◆ Chain() [2/3]

template<typename Derived>
template<typename OtherIter>
auto helios::utils::FunctionalAdapterBase< Derived >::Chain ( OtherIter begin,
OtherIter end ) const
inlinenodiscardconstexprnoexcept

Chains another range after this one.

Template Parameters
OtherIterIterator type of the other adapter
Parameters
beginBegin iterator of the other adapter
endEnd iterator of the other adapter
Returns
ChainAdapter that yields elements from both ranges

Definition at line 3712 of file functional_adapters.hpp.

◆ Chain() [3/3]

template<typename Derived>
template<typename R>
auto helios::utils::FunctionalAdapterBase< Derived >::Chain ( R & range) const
inlinenodiscardconstexprnoexcept

Chains another range after this one.

Template Parameters
RRange type of the other adapter
Parameters
rangeThe other range to chain
Returns
ChainAdapter that yields elements from both ranges

Definition at line 3729 of file functional_adapters.hpp.

◆ Collect()

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::Collect ( ) const
nodiscardconstexpr

Terminal operation: collects all elements into a vector.

Returns
Vector containing all elements

Definition at line 4333 of file functional_adapters.hpp.

◆ CollectWith() [1/3]

template<typename Derived>
template<typename Allocator>
auto helios::utils::FunctionalAdapterBase< Derived >::CollectWith ( Allocator allocator = {}) const
nodiscardconstexpr

Terminal operation: collects all elements into a vector with a custom allocator.

Template Parameters
AllocatorAllocator type
Parameters
allocatorAllocator to use for the vector
Returns
Vector containing all elements

Definition at line 4346 of file functional_adapters.hpp.

◆ CollectWith() [2/3]

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::CollectWith ( std::nullptr_t ) const
delete

◆ CollectWith() [3/3]

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::CollectWith ( std::pmr::memory_resource * resource) const
nodiscardconstexpr

Terminal operation: collects all elements into a vector with a specific memory resource.

Parameters
resourceMemory resource to use for the vector
Returns
Vector containing all elements

Definition at line 4359 of file functional_adapters.hpp.

◆ CountIf()

template<typename Derived>
template<typename Pred>
size_t helios::utils::FunctionalAdapterBase< Derived >::CountIf ( const Pred & predicate) const
nodiscardconstexpr

Terminal operation: counts elements satisfying a predicate.

Template Parameters
PredPredicate type
Parameters
predicateFunction to test elements
Returns
Number of elements that satisfy the predicate

Definition at line 4099 of file functional_adapters.hpp.

◆ Enumerate()

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::Enumerate ( ) const
inlinenodiscardconstexprnoexcept

Adds an index to each element.

Returns
EnumerateAdapter that pairs indices with values

Definition at line 3671 of file functional_adapters.hpp.

◆ Filter()

template<typename Derived>
template<typename Pred>
auto helios::utils::FunctionalAdapterBase< Derived >::Filter ( Pred predicate) const
inlinenodiscardconstexprnoexcept

Chains another filter operation on top of this iterator.

Template Parameters
PredPredicate type
Parameters
predicateFunction to filter elements
Returns
FilterAdapter that applies this adapter then filters

Definition at line 3592 of file functional_adapters.hpp.

◆ Find()

template<typename Derived>
template<typename Pred>
auto helios::utils::FunctionalAdapterBase< Derived >::Find ( const Pred & predicate) const
nodiscardconstexpr

Terminal operation: finds the first element satisfying a predicate.

Template Parameters
PredPredicate type
Parameters
predicateFunction to test elements
Returns
Optional or pointer to the element with maximum key, based on the iterator type

Definition at line 4069 of file functional_adapters.hpp.

◆ Fold()

template<typename Derived>
template<typename T, typename Folder>
T helios::utils::FunctionalAdapterBase< Derived >::Fold ( T init,
const Folder & folder ) const
nodiscardconstexpr

Terminal operation: reduces elements to a single value using a folder function.

Template Parameters
TAccumulator type
FolderFunction type that combines accumulator with each element
Parameters
initInitial accumulator value
folderFunction to fold elements
Returns
Final accumulated value

Definition at line 4050 of file functional_adapters.hpp.

◆ ForEach()

template<typename Derived>
template<typename Action>
void helios::utils::FunctionalAdapterBase< Derived >::ForEach ( const Action & action) const
constexpr

Terminal operation: applies an action to each element.

Template Parameters
ActionFunction type that processes each element
Parameters
actionFunction to apply to each element

Definition at line 4037 of file functional_adapters.hpp.

◆ GetDerived() [1/2]

template<typename Derived>
const Derived & helios::utils::FunctionalAdapterBase< Derived >::GetDerived ( ) const
inlinenodiscardconstexprprotectednoexcept

Gets const reference to derived class instance.

Returns
Const reference to derived class

Definition at line 4030 of file functional_adapters.hpp.

◆ GetDerived() [2/2]

template<typename Derived>
Derived & helios::utils::FunctionalAdapterBase< Derived >::GetDerived ( )
inlinenodiscardconstexprprotectednoexcept

Gets reference to derived class instance.

Returns
Reference to derived class

Definition at line 4022 of file functional_adapters.hpp.

◆ GroupBy()

template<typename Derived>
template<typename KeyFunc>
auto helios::utils::FunctionalAdapterBase< Derived >::GroupBy ( const KeyFunc & key_func) const
nodiscardconstexpr

Terminal operation: groups elements by a key function.

Template Parameters
KeyFuncKey extraction function type
Parameters
key_funcFunction to extract grouping key from each element
Returns
Map from keys to vectors of elements with that key

Definition at line 4275 of file functional_adapters.hpp.

◆ GroupByWith()

template<typename Derived>
template<typename KeyFunc, typename MapAllocator, typename ValueAllocator>
auto helios::utils::FunctionalAdapterBase< Derived >::GroupByWith ( const KeyFunc & key_func,
MapAllocator map_allocator,
ValueAllocator value_allocator ) const
nodiscardconstexpr

Terminal operation: groups elements by key with custom allocators.

Template Parameters
KeyFuncKey extraction function type
MapAllocatorAllocator for unordered_map nodes
ValueAllocatorAllocator for grouped vectors
Parameters
key_funcFunction to extract grouping key from each element
map_allocatorAllocator for map storage
value_allocatorAllocator for each grouped vector
Returns
Map from keys to vectors using provided allocators

Definition at line 4296 of file functional_adapters.hpp.

◆ Inspect()

template<typename Derived>
template<typename Func>
auto helios::utils::FunctionalAdapterBase< Derived >::Inspect ( Func inspector) const
inlinenodiscardconstexprnoexcept

Observes each element without modifying it.

Template Parameters
FuncInspector function type
Parameters
inspectorFunction to call on each element
Returns
InspectAdapter for side effects

Definition at line 3684 of file functional_adapters.hpp.

◆ Into()

template<typename Derived>
template<typename OutIt>
void helios::utils::FunctionalAdapterBase< Derived >::Into ( OutIt out) const
constexpr

Terminal operation: writes all elements into an output iterator.

Consumes the adapter and writes each element to the provided output iterator. This is more efficient than Collect() when you already have a destination container.

Template Parameters
OutItOutput iterator type
Parameters
outOutput iterator to write elements into
std::vector<int> results;
query.Filter([](int x) { return x > 5;
}).Into(std::back_inserter(results));
constexpr void Into(OutIt out) const
Terminal operation: writes all elements into an output iterator.

Definition at line 4367 of file functional_adapters.hpp.

◆ Map()

template<typename Derived>
template<typename Func>
auto helios::utils::FunctionalAdapterBase< Derived >::Map ( Func transform) const
inlinenodiscardconstexprnoexcept

Transforms each element using the given function.

Template Parameters
FuncTransformation function type
Parameters
transformFunction to apply to each element
Returns
MapAdapter that transforms adapted results

Definition at line 3607 of file functional_adapters.hpp.

◆ MaxBy()

template<typename Derived>
template<typename KeyFunc>
auto helios::utils::FunctionalAdapterBase< Derived >::MaxBy ( const KeyFunc & key_func) const
nodiscardconstexpr

Terminal operation: finds the element with the maximum value according to a key function.

Template Parameters
KeyFuncKey extraction function type
Parameters
key_funcFunction to extract comparison key from each element
Returns
Optional or pointer to the element with maximum key, based on the iterator type

Definition at line 4172 of file functional_adapters.hpp.

◆ MinBy()

template<typename Derived>
template<typename KeyFunc>
auto helios::utils::FunctionalAdapterBase< Derived >::MinBy ( const KeyFunc & key_func) const
nodiscardconstexpr

Terminal operation: finds the element with the minimum value according to a key function.

Template Parameters
KeyFuncKey extraction function type
Parameters
key_funcFunction to extract comparison key from each element
Returns
Optional or pointer to the element with maximum key, based on the iterator type

Definition at line 4223 of file functional_adapters.hpp.

◆ None()

template<typename Derived>
template<typename Pred>
bool helios::utils::FunctionalAdapterBase< Derived >::None ( const Pred & predicate) const
inlinenodiscardconstexpr

Terminal operation: checks if no elements satisfy a predicate.

Template Parameters
PredPredicate type
Parameters
predicateFunction to test elements
Returns
True if no elements satisfy the predicate, false otherwise

Definition at line 4013 of file functional_adapters.hpp.

◆ Partition()

template<typename Derived>
template<typename Pred>
auto helios::utils::FunctionalAdapterBase< Derived >::Partition ( const Pred & predicate) const
nodiscardconstexpr

Terminal operation: partitions elements into two groups based on a predicate.

Template Parameters
PredPredicate type
Parameters
predicateFunction to test elements
Returns
Pair of vectors: first contains elements satisfying predicate, second contains the rest

Definition at line 4118 of file functional_adapters.hpp.

◆ PartitionWith()

template<typename Derived>
requires std::same_as<typename Allocator::value_type, std::iter_value_t<Derived>>
template<typename Pred, typename Allocator>
requires std::same_as<typename Allocator::value_type, std::iter_value_t<Derived>>
auto helios::utils::FunctionalAdapterBase< Derived >::PartitionWith ( const Pred & predicate,
Allocator allocator ) const
nodiscardconstexpr

Terminal operation: partitions elements with a custom allocator.

Template Parameters
PredPredicate type
AllocatorAllocator for result vectors
Parameters
predicateFunction to test elements
allocatorAllocator to use for both result vectors
Returns
Pair of vectors using the provided allocator

Definition at line 4146 of file functional_adapters.hpp.

◆ Reverse()

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::Reverse ( ) const
inlinenodiscardconstexprnoexcept

Reverses the order of elements.

Note
Requires bidirectional iterator support
Returns
ReverseAdapter that yields elements in reverse order

Definition at line 3755 of file functional_adapters.hpp.

◆ Skip()

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::Skip ( size_t count) const
inlinenodiscardconstexprnoexcept

Skips the first count elements.

Parameters
countNumber of elements to skip
Returns
SkipAdapter that skips adapted results

Definition at line 3632 of file functional_adapters.hpp.

◆ SkipWhile()

template<typename Derived>
template<typename Pred>
auto helios::utils::FunctionalAdapterBase< Derived >::SkipWhile ( Pred predicate) const
inlinenodiscardconstexprnoexcept

Skips elements while a predicate is true.

Template Parameters
PredPredicate type for skip-while operation
Parameters
predicatePredicate to determine when to stop skipping
Returns
SkipWhileAdapter that conditionally skips elements

Definition at line 3660 of file functional_adapters.hpp.

◆ Slide()

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::Slide ( size_t window_size) const
inlinenodiscardconstexprnoexcept

Creates sliding windows over elements.

Parameters
window_sizeSize of the sliding window
Returns
SlideAdapter that yields windows of elements
Warning
window_size must be greater than 0

Definition at line 3767 of file functional_adapters.hpp.

◆ StepBy()

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::StepBy ( size_t step) const
inlinenodiscardconstexprnoexcept

Takes every Nth element.

Parameters
stepStep size between elements
Returns
StepByAdapter that skips elements

Definition at line 3697 of file functional_adapters.hpp.

◆ Stride()

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::Stride ( size_t stride) const
inlinenodiscardconstexprnoexcept

Takes every Nth element with stride.

Parameters
strideNumber of elements to skip between yields
Returns
StrideAdapter that yields every Nth element
Warning
stride must be greater than 0

Definition at line 3781 of file functional_adapters.hpp.

◆ Take()

template<typename Derived>
auto helios::utils::FunctionalAdapterBase< Derived >::Take ( size_t count) const
inlinenodiscardconstexprnoexcept

Limits the number of elements to at most count.

Parameters
countMaximum number of elements to yield
Returns
TakeAdapter that limits adapted results

Definition at line 3620 of file functional_adapters.hpp.

◆ TakeWhile()

template<typename Derived>
template<typename Pred>
auto helios::utils::FunctionalAdapterBase< Derived >::TakeWhile ( Pred predicate) const
inlinenodiscardconstexprnoexcept

Takes elements while a predicate is true.

Template Parameters
PredPredicate type for take-while operation
Parameters
predicatePredicate to determine when to stop taking
Returns
TakeWhileAdapter that conditionally takes elements

Definition at line 3646 of file functional_adapters.hpp.

◆ Zip() [1/3]

template<typename Derived>
template<typename R>
auto helios::utils::FunctionalAdapterBase< Derived >::Zip ( const R & range) const
inlinenodiscardconstexprnoexcept

Zips another range with this one.

Template Parameters
ROther range
Parameters
rangeThe other range to zip with
Returns
ZipAdapter that

Definition at line 3827 of file functional_adapters.hpp.

◆ Zip() [2/3]

template<typename Derived>
template<typename OtherIter>
auto helios::utils::FunctionalAdapterBase< Derived >::Zip ( OtherIter begin,
OtherIter end ) const
inlinenodiscardconstexprnoexcept

Zips another range with this one.

Template Parameters
OtherIterIterator type to zip with
Parameters
beginBegin iterator for the other range
endEnd iterator for the other range
Returns
ZipAdapter that yields tuples of corresponding elements

Definition at line 3796 of file functional_adapters.hpp.

◆ Zip() [3/3]

template<typename Derived>
template<typename R>
auto helios::utils::FunctionalAdapterBase< Derived >::Zip ( R & range) const
inlinenodiscardconstexprnoexcept

Zips another range with this one.

Template Parameters
ROther range
Parameters
rangeThe other range to zip with
Returns
ZipAdapter that

Definition at line 3813 of file functional_adapters.hpp.