Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
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(ChainAdapterFromRange(GetDerived(), range)))
 Chains another range after this one.
 
template<typename R >
constexpr auto Chain (const R &range) const noexcept(noexcept(ChainAdapterFromRange(GetDerived(), 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(ZipAdapterFromRange(GetDerived(), range)))
 Zips another range with this one.
 
template<typename R >
constexpr auto Zip (const R &range) const noexcept(noexcept(ZipAdapterFromRange(GetDerived(), 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 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.
 
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 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.
 
constexpr auto Collect () const
 Terminal operation: collects all elements into a vector.
 
template<typename OutIt >
constexpr void Into (OutIt out) const
 

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 2702 of file functional_adapters.hpp.

Member Function Documentation

◆ All()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3095 of file functional_adapters.hpp.

3095 {
3096 for (auto&& value : GetDerived()) {
3097 bool result = false;
3098 if constexpr (std::invocable<Pred, decltype(value)>) {
3099 result = predicate(std::forward<decltype(value)>(value));
3100 } else {
3101 result = std::apply(predicate, std::forward<decltype(value)>(value));
3102 }
3103 if (!result) {
3104 return false;
3105 }
3106 }
3107 return true;
3108}
constexpr Derived & GetDerived() noexcept
Gets reference to derived class instance.

◆ Any()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3078 of file functional_adapters.hpp.

3078 {
3079 for (auto&& value : GetDerived()) {
3080 bool result = false;
3081 if constexpr (std::invocable<Pred, decltype(value)>) {
3082 result = predicate(std::forward<decltype(value)>(value));
3083 } else {
3084 result = std::apply(predicate, std::forward<decltype(value)>(value));
3085 }
3086 if (result) {
3087 return true;
3088 }
3089 }
3090 return false;
3091}

◆ Chain() [1/3]

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

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 2838 of file functional_adapters.hpp.

2839 {
2840 return ChainAdapterFromRange(GetDerived(), range);
2841 }
constexpr auto ChainAdapterFromRange(R1 &range1, R2 &range2) noexcept(noexcept(ChainAdapter< std::ranges::iterator_t< R1 >, std::ranges::iterator_t< R2 > >(std::ranges::begin(range1), std::ranges::end(range1), std::ranges::begin(range2), std::ranges::end(range2)))) -> ChainAdapter< std::ranges::iterator_t< R1 >, std::ranges::iterator_t< R2 > >
Helper function to create a ChainAdapter from two non-const ranges.

◆ Chain() [2/3]

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2814 of file functional_adapters.hpp.

2816 {
2817 return ChainAdapter<Derived, OtherIter>(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end));
2818 }

◆ Chain() [3/3]

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

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 2827 of file functional_adapters.hpp.

2827 {
2828 return ChainAdapterFromRange(GetDerived(), range);
2829 }

◆ Collect()

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

Terminal operation: collects all elements into a vector.

Returns
Vector containing all elements
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3147 of file functional_adapters.hpp.

3147 {
3148 using ValueType = std::iter_value_t<Derived>;
3149 std::vector<ValueType> result;
3150 result.reserve(static_cast<size_t>(std::distance(GetDerived().begin(), GetDerived().end())));
3151 for (auto&& value : GetDerived()) {
3152 result.push_back(std::forward<decltype(value)>(value));
3153 }
3154 return result;
3155}

◆ CountIf()

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

Terminal operation: counts elements satisfying a predicate.

Template Parameters
PredPredicate type
Parameters
predicateFunction to test elements
Returns
Number of elements that satisfy the predicate
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3130 of file functional_adapters.hpp.

3130 {
3131 size_t count = 0;
3132 for (auto&& value : GetDerived()) {
3133 bool result = false;
3134 if constexpr (std::invocable<Pred, decltype(value)>) {
3135 result = predicate(std::forward<decltype(value)>(value));
3136 } else {
3137 result = std::apply(predicate, std::forward<decltype(value)>(value));
3138 }
3139 if (result) {
3140 ++count;
3141 }
3142 }
3143 return count;
3144}

◆ Enumerate()

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

Adds an index to each element.

Returns
EnumerateAdapter that pairs indices with values
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2778 of file functional_adapters.hpp.

2779 {
2780 return EnumerateAdapter<Derived>(GetDerived().begin(), GetDerived().end());
2781 }

◆ Filter()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2711 of file functional_adapters.hpp.

2712 {
2713 return FilterAdapter<Derived, Pred>(GetDerived().begin(), GetDerived().end(), std::move(predicate));
2714 }

◆ Find()

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

Terminal operation: finds the first element satisfying a predicate.

Template Parameters
PredPredicate type
Parameters
predicateFunction to test elements
Returns
Optional containing the first matching element, or empty if none found
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3112 of file functional_adapters.hpp.

3112 {
3113 using ValueType = std::iter_value_t<Derived>;
3114 for (auto&& value : GetDerived()) {
3115 bool result = false;
3116 if constexpr (std::invocable<Pred, decltype(value)>) {
3117 result = predicate(std::forward<decltype(value)>(value));
3118 } else {
3119 result = std::apply(predicate, std::forward<decltype(value)>(value));
3120 }
3121 if (result) {
3122 return std::optional<ValueType>(std::forward<decltype(value)>(value));
3123 }
3124 }
3125 return std::optional<ValueType>{};
3126}

◆ Fold()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3063 of file functional_adapters.hpp.

3063 {
3064 for (auto&& value : GetDerived()) {
3065 if constexpr (std::invocable<Folder, T&&, decltype(value)>) {
3066 init = folder(std::move(init), std::forward<decltype(value)>(value));
3067 } else {
3068 init = std::apply(
3069 [&init, &folder](auto&&... args) { return folder(std::move(init), std::forward<decltype(args)>(args)...); },
3070 std::forward<decltype(value)>(value));
3071 }
3072 }
3073 return init;
3074}

◆ ForEach()

template<typename Derived >
template<typename Action >
constexpr 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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3051 of file functional_adapters.hpp.

3051 {
3052 for (auto&& value : GetDerived()) {
3053 if constexpr (std::invocable<Action, decltype(value)>) {
3054 action(std::forward<decltype(value)>(value));
3055 } else {
3056 std::apply(action, std::forward<decltype(value)>(value));
3057 }
3058 }
3059}

◆ GetDerived() [1/2]

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

Gets const reference to derived class instance.

Returns
Const reference to derived class

Definition at line 3046 of file functional_adapters.hpp.

3046{ return static_cast<const Derived&>(*this); }

◆ GetDerived() [2/2]

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

Gets reference to derived class instance.

Returns
Reference to derived class
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3040 of file functional_adapters.hpp.

3040{ return static_cast<Derived&>(*this); }

◆ GroupBy()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3268 of file functional_adapters.hpp.

3268 {
3269 using ValueType = std::iter_value_t<Derived>;
3270 using KeyType = std::decay_t<std::invoke_result_t<KeyFunc, ValueType>>;
3271 std::unordered_map<KeyType, std::vector<ValueType>> groups;
3272
3273 for (auto&& value : GetDerived()) {
3274 KeyType key;
3275 if constexpr (std::invocable<KeyFunc, decltype(value)>) {
3276 key = key_func(std::forward<decltype(value)>(value));
3277 } else {
3278 key = std::apply(key_func, std::forward<decltype(value)>(value));
3279 }
3280 groups[std::move(key)].push_back(std::forward<decltype(value)>(value));
3281 }
3282
3283 return groups;
3284}

◆ Inspect()

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

Observes each element without modifying it.

Template Parameters
FuncInspector function type
Parameters
inspectorFunction to call on each element
Returns
InspectAdapter for side effects
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2790 of file functional_adapters.hpp.

2792 {
2793 return InspectAdapter<Derived, Func>(GetDerived().begin(), GetDerived().end(), std::move(inspector));
2794 }

◆ Into()

template<typename Derived >
template<typename OutIt >
constexpr void helios::utils::FunctionalAdapterBase< Derived >::Into ( OutIt  out) const
constexpr
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3159 of file functional_adapters.hpp.

3159 {
3160 for (auto&& value : GetDerived()) {
3161 *out++ = std::forward<decltype(value)>(value);
3162 }
3163}

◆ Map()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2723 of file functional_adapters.hpp.

2724 {
2725 return MapAdapter<Derived, Func>(GetDerived().begin(), GetDerived().end(), std::move(transform));
2726 }

◆ MaxBy()

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

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 containing the element with maximum key, or empty if no elements
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3192 of file functional_adapters.hpp.

3192 {
3193 using ValueType = std::iter_value_t<Derived>;
3194 auto iter = GetDerived().begin();
3195 const auto end_iter = GetDerived().end();
3196
3197 if (iter == end_iter) {
3198 return std::nullopt;
3199 }
3200
3201 std::optional<ValueType> max_element;
3202 max_element.emplace(*iter);
3203
3204 auto get_key = [&key_func](auto&& val) {
3205 if constexpr (std::invocable<KeyFunc, decltype(val)>) {
3206 return key_func(std::forward<decltype(val)>(val));
3207 } else {
3208 return std::apply(key_func, std::forward<decltype(val)>(val));
3209 }
3210 };
3211
3212 auto max_key = get_key(*max_element);
3213 ++iter;
3214
3215 while (iter != end_iter) {
3216 auto current = *iter;
3217 auto current_key = get_key(current);
3218 if (current_key > max_key) {
3219 max_key = current_key;
3220 max_element.emplace(current);
3221 }
3222 ++iter;
3223 }
3224
3225 return max_element;
3226}

◆ MinBy()

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

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 containing the element with minimum key, or empty if no elements
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3230 of file functional_adapters.hpp.

3230 {
3231 using ValueType = std::iter_value_t<Derived>;
3232 auto iter = GetDerived().begin();
3233 const auto end_iter = GetDerived().end();
3234
3235 if (iter == end_iter) {
3236 return std::nullopt;
3237 }
3238
3239 std::optional<ValueType> min_element;
3240 min_element.emplace(*iter);
3241
3242 auto get_key = [&key_func](auto&& val) {
3243 if constexpr (std::invocable<KeyFunc, decltype(val)>) {
3244 return key_func(std::forward<decltype(val)>(val));
3245 } else {
3246 return std::apply(key_func, std::forward<decltype(val)>(val));
3247 }
3248 };
3249
3250 auto min_key = get_key(*min_element);
3251 ++iter;
3252
3253 while (iter != end_iter) {
3254 auto current = *iter;
3255 auto current_key = get_key(current);
3256 if (current_key < min_key) {
3257 min_key = current_key;
3258 min_element.emplace(current);
3259 }
3260 ++iter;
3261 }
3262
3263 return min_element;
3264}

◆ None()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2955 of file functional_adapters.hpp.

2955 {
2956 return !Any(predicate);
2957 }
constexpr bool Any(const Pred &predicate) const
Terminal operation: checks if any element satisfies a predicate.

◆ Partition()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 3167 of file functional_adapters.hpp.

3167 {
3168 using ValueType = std::iter_value_t<Derived>;
3169 std::vector<ValueType> matched;
3170 std::vector<ValueType> not_matched;
3171
3172 for (auto&& value : GetDerived()) {
3173 bool result = false;
3174 if constexpr (std::invocable<Pred, decltype(value)>) {
3175 result = predicate(std::forward<decltype(value)>(value));
3176 } else {
3177 result = std::apply(predicate, std::forward<decltype(value)>(value));
3178 }
3179
3180 if (result) {
3181 matched.push_back(std::forward<decltype(value)>(value));
3182 } else {
3183 not_matched.push_back(std::forward<decltype(value)>(value));
3184 }
3185 }
3186
3187 return std::pair{std::move(matched), std::move(not_matched)};
3188}

◆ Reverse()

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

Reverses the order of elements.

Note
Requires bidirectional iterator support
Returns
ReverseAdapter that yields elements in reverse order
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2848 of file functional_adapters.hpp.

2849 {
2850 return ReverseAdapter<Derived>(GetDerived().begin(), GetDerived().end());
2851 }

◆ Skip()

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

Skips the first count elements.

Parameters
countNumber of elements to skip
Returns
SkipAdapter that skips adapted results
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2743 of file functional_adapters.hpp.

2744 {
2745 return SkipAdapter<Derived>(GetDerived().begin(), GetDerived().end(), count);
2746 }

◆ SkipWhile()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2768 of file functional_adapters.hpp.

2770 {
2771 return SkipWhileAdapter<Derived, Pred>(GetDerived().begin(), GetDerived().end(), std::move(predicate));
2772 }

◆ Slide()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2859 of file functional_adapters.hpp.

2860 {
2861 return SlideAdapter<Derived>(GetDerived().begin(), GetDerived().end(), window_size);
2862 }

◆ StepBy()

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

Takes every Nth element.

Parameters
stepStep size between elements
Returns
StepByAdapter that skips elements
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2801 of file functional_adapters.hpp.

2802 {
2803 return StepByAdapter<Derived>(GetDerived().begin(), GetDerived().end(), step);
2804 }

◆ Stride()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2870 of file functional_adapters.hpp.

2871 {
2872 return StrideAdapter<Derived>(GetDerived().begin(), GetDerived().end(), stride);
2873 }

◆ Take()

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

Limits the number of elements to at most count.

Parameters
countMaximum number of elements to yield
Returns
TakeAdapter that limits adapted results
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2733 of file functional_adapters.hpp.

2734 {
2735 return TakeAdapter<Derived>(GetDerived().begin(), GetDerived().end(), count);
2736 }

◆ TakeWhile()

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2755 of file functional_adapters.hpp.

2757 {
2758 return TakeWhileAdapter<Derived, Pred>(GetDerived().begin(), GetDerived().end(), std::move(predicate));
2759 }

◆ Zip() [1/3]

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

Zips another range with this one.

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

Definition at line 2907 of file functional_adapters.hpp.

2907 {
2908 return ZipAdapterFromRange(GetDerived(), range);
2909 }
constexpr auto ZipAdapterFromRange(R1 &range1, R2 &range2) noexcept(noexcept(ZipAdapter< std::ranges::iterator_t< R1 >, std::ranges::iterator_t< R2 > >(std::ranges::begin(range1), std::ranges::end(range1), std::ranges::begin(range2), std::ranges::end(range2)))) -> ZipAdapter< std::ranges::iterator_t< R1 >, std::ranges::iterator_t< R2 > >
Helper function to create a ZipAdapter from two ranges.

◆ Zip() [2/3]

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

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
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2883 of file functional_adapters.hpp.

2885 {
2886 return ZipAdapter<Derived, OtherIter>(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move((end)));
2887 }

◆ Zip() [3/3]

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

Zips another range with this one.

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

Definition at line 2896 of file functional_adapters.hpp.

2896 {
2897 return ZipAdapterFromRange(GetDerived(), range);
2898 }