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

Iterator adapter that takes elements while a predicate returns true. More...

#include <functional_adapters.hpp>

Inheritance diagram for helios::utils::TakeWhileAdapter< Iter, Pred >:
helios::utils::FunctionalAdapterBase< TakeWhileAdapter< Iter, Pred > >

Public Types

using iterator_concept = details::adapter_iterator_concept_t<Iter>
using iterator_category = details::adapter_iterator_category_t<Iter>
using value_type = std::iter_value_t<Iter>
using reference = value_type
using pointer = void
using difference_type = std::iter_difference_t<Iter>

Public Member Functions

constexpr TakeWhileAdapter (Iter begin, Iter end, Pred predicate) noexcept(std::is_nothrow_move_constructible_v< Iter > &&std::is_nothrow_copy_constructible_v< Iter > &&std::is_nothrow_move_constructible_v< Pred > &&noexcept(CheckPredicate()))
 Constructs a take-while adapter with the given iterator range and predicate.
template<ExternalRange R>
requires TakeWhileAdapterRequirements<std::ranges::iterator_t<R>, Pred>
constexpr TakeWhileAdapter (R &range, Pred predicate) noexcept(noexcept(TakeWhileAdapter(std::ranges::begin(range), std::ranges::end(range), std::move(predicate))))
 Constructs a take-while adapter from a range and predicate.
template<ExternalRange R>
requires TakeWhileAdapterRequirements<std::ranges::iterator_t<const R>, Pred>
constexpr TakeWhileAdapter (const R &range, Pred predicate) noexcept(noexcept(TakeWhileAdapter(std::ranges::cbegin(range), std::ranges::cend(range), std::move(predicate))))
 Constructs a take-while adapter from a const range and predicate.
constexpr TakeWhileAdapter (const TakeWhileAdapter &) noexcept(std::is_nothrow_copy_constructible_v< Iter > &&std::is_nothrow_copy_constructible_v< Pred >)=default
constexpr TakeWhileAdapter (TakeWhileAdapter &&) noexcept(std::is_nothrow_move_constructible_v< Iter > &&std::is_nothrow_move_constructible_v< Pred >)=default
constexpr ~TakeWhileAdapter () noexcept(std::is_nothrow_destructible_v< Iter > &&std::is_nothrow_destructible_v< Pred >)=default
constexpr TakeWhileAdapteroperator= (const TakeWhileAdapter &) noexcept(std::is_nothrow_copy_assignable_v< Iter > &&std::is_nothrow_copy_assignable_v< Pred >)=default
constexpr TakeWhileAdapteroperator= (TakeWhileAdapter &&) noexcept(std::is_nothrow_move_assignable_v< Iter > &&std::is_nothrow_move_assignable_v< Pred >)=default
constexpr TakeWhileAdapteroperator++ () noexcept(noexcept(++std::declval< Iter & >()) &&noexcept(std::declval< Iter & >() !=std::declval< Iter & >()) &&noexcept(CheckPredicate()))
constexpr TakeWhileAdapter operator++ (int) noexcept(std::is_nothrow_copy_constructible_v< TakeWhileAdapter > &&noexcept(++std::declval< TakeWhileAdapter & >()))
constexpr reference operator* () const noexcept(noexcept(*std::declval< const Iter & >()))
pointer operator-> () const =delete
constexpr bool operator== (const TakeWhileAdapter &other) const noexcept(noexcept(std::declval< const Iter & >()==std::declval< const Iter & >()))
constexpr bool operator!= (const TakeWhileAdapter &other) const noexcept(noexcept(std::declval< const TakeWhileAdapter & >()==std::declval< const TakeWhileAdapter & >()))
constexpr bool IsAtEnd () const noexcept(noexcept(std::declval< const Iter & >()==std::declval< const Iter & >()))
 Checks if the iterator has reached the end.
constexpr TakeWhileAdapter begin () const noexcept(std::is_nothrow_copy_constructible_v< TakeWhileAdapter >)
constexpr TakeWhileAdapter end () const noexcept(std::is_nothrow_copy_constructible_v< TakeWhileAdapter >)
Public Member Functions inherited from helios::utils::FunctionalAdapterBase< TakeWhileAdapter< Iter, Pred > >
constexpr auto Filter (Pred predicate) const noexcept(noexcept(FilterAdapter< TakeWhileAdapter< Iter, Pred >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Chains another filter operation on top of this iterator.
constexpr auto Map (Func transform) const noexcept(noexcept(MapAdapter< TakeWhileAdapter< Iter, Pred >, 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< TakeWhileAdapter< Iter, Pred > >(GetDerived().begin(), GetDerived().end(), count)))
 Limits the number of elements to at most count.
constexpr auto Skip (size_t count) const noexcept(noexcept(SkipAdapter< TakeWhileAdapter< Iter, Pred > >(GetDerived().begin(), GetDerived().end(), count)))
 Skips the first count elements.
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.
constexpr auto SkipWhile (Pred predicate) const noexcept(noexcept(SkipWhileAdapter< TakeWhileAdapter< Iter, Pred >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Skips elements while a predicate is true.
constexpr auto Enumerate () const noexcept(noexcept(EnumerateAdapter< TakeWhileAdapter< Iter, Pred > >(GetDerived().begin(), GetDerived().end())))
 Adds an index to each element.
constexpr auto Inspect (Func inspector) const noexcept(noexcept(InspectAdapter< TakeWhileAdapter< Iter, Pred >, Func >(GetDerived().begin(), GetDerived().end(), std::move(inspector))))
 Observes each element without modifying it.
constexpr auto StepBy (size_t step) const noexcept(noexcept(StepByAdapter< TakeWhileAdapter< Iter, Pred > >(GetDerived().begin(), GetDerived().end(), step)))
 Takes every Nth element.
constexpr auto Chain (OtherIter begin, OtherIter end) const noexcept(noexcept(ChainAdapter< TakeWhileAdapter< Iter, Pred >, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Chains another range after this one.
constexpr auto Reverse () const noexcept(noexcept(ReverseAdapter< TakeWhileAdapter< Iter, Pred > >(GetDerived().begin(), GetDerived().end())))
 Reverses the order of elements.
constexpr auto Slide (size_t window_size) const noexcept(noexcept(SlideAdapter< TakeWhileAdapter< Iter, Pred > >(GetDerived().begin(), GetDerived().end(), window_size)))
 Creates sliding windows over elements.
constexpr auto Stride (size_t stride) const noexcept(noexcept(StrideAdapter< TakeWhileAdapter< Iter, Pred > >(GetDerived().begin(), GetDerived().end(), stride)))
 Takes every Nth element with stride.
constexpr auto Zip (OtherIter begin, OtherIter end) const noexcept(noexcept(ZipAdapter< TakeWhileAdapter< Iter, Pred >, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Zips another range with this one.
constexpr void ForEach (const Action &action) const
 Terminal operation: applies an action to each element.
constexpr T Fold (T init, const Folder &folder) const
 Terminal operation: reduces elements to a single value using a folder function.
constexpr auto Find (const Pred &predicate) const
 Terminal operation: finds the first element satisfying a predicate.
constexpr size_t CountIf (const Pred &predicate) const
 Terminal operation: counts elements satisfying a predicate.
constexpr auto Partition (const Pred &predicate) const
 Terminal operation: partitions elements into two groups based on a predicate.
constexpr auto PartitionWith (const Pred &predicate, Allocator allocator) const
 Terminal operation: partitions elements with a custom allocator.
constexpr auto MaxBy (const KeyFunc &key_func) const
 Terminal operation: finds the element with the maximum value according to a key function.
constexpr auto MinBy (const KeyFunc &key_func) const
 Terminal operation: finds the element with the minimum value according to a key function.
constexpr auto GroupBy (const KeyFunc &key_func) const
 Terminal operation: groups elements by a key function.
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.
constexpr auto CollectWith (Allocator allocator={}) const
 Terminal operation: collects all elements into a vector with a custom allocator.
constexpr void Into (OutIt out) const
 Terminal operation: writes all elements into an output iterator.
constexpr bool Any (const Pred &predicate) const
 Terminal operation: checks if any element satisfies a predicate.
constexpr bool All (const Pred &predicate) const
 Terminal operation: checks if all elements satisfy a predicate.
constexpr bool None (const Pred &predicate) const
 Terminal operation: checks if no elements satisfy a predicate.

Additional Inherited Members

Protected Member Functions inherited from helios::utils::FunctionalAdapterBase< TakeWhileAdapter< Iter, Pred > >
constexpr TakeWhileAdapter< Iter, Pred > & GetDerived () noexcept
 Gets reference to derived class instance.

Detailed Description

template<typename Iter, typename Pred>
requires TakeWhileAdapterRequirements<Iter, Pred>
class helios::utils::TakeWhileAdapter< Iter, Pred >

Iterator adapter that takes elements while a predicate returns true.

This adapter yields elements as long as the predicate returns true. Once the predicate returns false, no more elements are yielded.

Template Parameters
IterUnderlying iterator type
PredPredicate function type
// Take entities while their health is above zero
auto alive_entities = query.TakeWhile([](const Health& h) { return h.points >
0; });

Definition at line 1186 of file functional_adapters.hpp.

Member Typedef Documentation

◆ difference_type

template<typename Iter, typename Pred>
using helios::utils::TakeWhileAdapter< Iter, Pred >::difference_type = std::iter_difference_t<Iter>

Definition at line 1194 of file functional_adapters.hpp.

◆ iterator_category

template<typename Iter, typename Pred>
using helios::utils::TakeWhileAdapter< Iter, Pred >::iterator_category = details::adapter_iterator_category_t<Iter>

Definition at line 1190 of file functional_adapters.hpp.

◆ iterator_concept

template<typename Iter, typename Pred>
using helios::utils::TakeWhileAdapter< Iter, Pred >::iterator_concept = details::adapter_iterator_concept_t<Iter>

Definition at line 1189 of file functional_adapters.hpp.

◆ pointer

template<typename Iter, typename Pred>
using helios::utils::TakeWhileAdapter< Iter, Pred >::pointer = void

Definition at line 1193 of file functional_adapters.hpp.

◆ reference

template<typename Iter, typename Pred>
using helios::utils::TakeWhileAdapter< Iter, Pred >::reference = value_type

Definition at line 1192 of file functional_adapters.hpp.

◆ value_type

template<typename Iter, typename Pred>
using helios::utils::TakeWhileAdapter< Iter, Pred >::value_type = std::iter_value_t<Iter>

Definition at line 1191 of file functional_adapters.hpp.

Constructor & Destructor Documentation

◆ TakeWhileAdapter() [1/5]

template<typename Iter, typename Pred>
helios::utils::TakeWhileAdapter< Iter, Pred >::TakeWhileAdapter ( Iter begin,
Iter end,
Pred predicate )
inlineconstexprnoexcept

Constructs a take-while adapter with the given iterator range and predicate.

Parameters
beginStart of the iterator range
endEnd of the iterator range
predicateFunction to test elements

Definition at line 1203 of file functional_adapters.hpp.

◆ TakeWhileAdapter() [2/5]

template<typename Iter, typename Pred>
template<ExternalRange R>
requires TakeWhileAdapterRequirements<std::ranges::iterator_t<R>, Pred>
helios::utils::TakeWhileAdapter< Iter, Pred >::TakeWhileAdapter ( R & range,
Pred predicate )
inlineconstexprnoexcept

Constructs a take-while adapter from a range and predicate.

Template Parameters
RThe type of the input range
Parameters
rangeThe input range to adapt
predicateFunction to test elements

Definition at line 1222 of file functional_adapters.hpp.

◆ TakeWhileAdapter() [3/5]

template<typename Iter, typename Pred>
template<ExternalRange R>
requires TakeWhileAdapterRequirements<std::ranges::iterator_t<const R>, Pred>
helios::utils::TakeWhileAdapter< Iter, Pred >::TakeWhileAdapter ( const R & range,
Pred predicate )
inlineconstexprnoexcept

Constructs a take-while adapter from a const range and predicate.

Template Parameters
RThe type of the input range
Parameters
rangeThe input range to adapt
predicateFunction to test elements

Definition at line 1237 of file functional_adapters.hpp.

◆ TakeWhileAdapter() [4/5]

template<typename Iter, typename Pred>
helios::utils::TakeWhileAdapter< Iter, Pred >::TakeWhileAdapter ( const TakeWhileAdapter< Iter, Pred > & ) const &&
constexprdefaultnoexcept

◆ TakeWhileAdapter() [5/5]

template<typename Iter, typename Pred>
helios::utils::TakeWhileAdapter< Iter, Pred >::TakeWhileAdapter ( TakeWhileAdapter< Iter, Pred > && ) const &&
constexprdefaultnoexcept

◆ ~TakeWhileAdapter()

template<typename Iter, typename Pred>
helios::utils::TakeWhileAdapter< Iter, Pred >::~TakeWhileAdapter ( ) &&
constexprdefaultnoexcept

Member Function Documentation

◆ begin()

template<typename Iter, typename Pred>
TakeWhileAdapter helios::utils::TakeWhileAdapter< Iter, Pred >::begin ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 1298 of file functional_adapters.hpp.

◆ end()

template<typename Iter, typename Pred>
requires TakeWhileAdapterRequirements<Iter, Pred>
auto helios::utils::TakeWhileAdapter< Iter, Pred >::end ( ) const
nodiscardconstexprnoexcept

Definition at line 1352 of file functional_adapters.hpp.

◆ IsAtEnd()

template<typename Iter, typename Pred>
bool helios::utils::TakeWhileAdapter< Iter, Pred >::IsAtEnd ( ) const
inlinenodiscardconstexprnoexcept

Checks if the iterator has reached the end.

Returns
True if at end, false otherwise

Definition at line 1292 of file functional_adapters.hpp.

◆ operator!=()

template<typename Iter, typename Pred>
bool helios::utils::TakeWhileAdapter< Iter, Pred >::operator!= ( const TakeWhileAdapter< Iter, Pred > & other) const
inlinenodiscardconstexprnoexcept

Definition at line 1282 of file functional_adapters.hpp.

◆ operator*()

template<typename Iter, typename Pred>
reference helios::utils::TakeWhileAdapter< Iter, Pred >::operator* ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 1268 of file functional_adapters.hpp.

◆ operator++() [1/2]

template<typename Iter, typename Pred>
requires TakeWhileAdapterRequirements<Iter, Pred>
auto helios::utils::TakeWhileAdapter< Iter, Pred >::operator++ ( )
constexprnoexcept

Definition at line 1329 of file functional_adapters.hpp.

◆ operator++() [2/2]

template<typename Iter, typename Pred>
requires TakeWhileAdapterRequirements<Iter, Pred>
auto helios::utils::TakeWhileAdapter< Iter, Pred >::operator++ ( int )
nodiscardconstexprnoexcept

Definition at line 1342 of file functional_adapters.hpp.

◆ operator->()

template<typename Iter, typename Pred>
pointer helios::utils::TakeWhileAdapter< Iter, Pred >::operator-> ( ) const
delete

◆ operator=() [1/2]

template<typename Iter, typename Pred>
TakeWhileAdapter & helios::utils::TakeWhileAdapter< Iter, Pred >::operator= ( const TakeWhileAdapter< Iter, Pred > & ) &&
constexprdefaultnoexcept

◆ operator=() [2/2]

template<typename Iter, typename Pred>
TakeWhileAdapter & helios::utils::TakeWhileAdapter< Iter, Pred >::operator= ( TakeWhileAdapter< Iter, Pred > && ) &&
constexprdefaultnoexcept

◆ operator==()

template<typename Iter, typename Pred>
bool helios::utils::TakeWhileAdapter< Iter, Pred >::operator== ( const TakeWhileAdapter< Iter, Pred > & other) const
inlinenodiscardconstexprnoexcept

Definition at line 1275 of file functional_adapters.hpp.