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

#include <functional_adapters.hpp>

Inheritance diagram for helios::utils::TakeAdapter< Iter >:
helios::utils::FunctionalAdapterBase< TakeAdapter< Iter > >

Public Types

using iterator_category = std::forward_iterator_tag
 
using value_type = std::iter_value_t< Iter >
 
using difference_type = std::iter_difference_t< Iter >
 
using pointer = value_type *
 
using reference = value_type
 

Public Member Functions

constexpr TakeAdapter (Iter begin, Iter end, size_t count) noexcept(std::is_nothrow_move_constructible_v< Iter > &&std::is_nothrow_copy_constructible_v< Iter >)
 Constructs a take adapter with the given iterator range and count.
 
constexpr TakeAdapter (const TakeAdapter &) noexcept(std::is_nothrow_copy_constructible_v< Iter >)=default
 
constexpr TakeAdapter (TakeAdapter &&) noexcept(std::is_nothrow_move_constructible_v< Iter >)=default
 
constexpr ~TakeAdapter () noexcept(std::is_nothrow_destructible_v< Iter >)=default
 
constexpr TakeAdapteroperator= (const TakeAdapter &) noexcept(std::is_nothrow_copy_assignable_v< Iter >)=default
 
constexpr TakeAdapteroperator= (TakeAdapter &&) noexcept(std::is_nothrow_move_assignable_v< Iter >)=default
 
constexpr TakeAdapteroperator++ () noexcept(noexcept(++std::declval< Iter & >()))
 
constexpr TakeAdapter operator++ (int) noexcept(std::is_nothrow_copy_constructible_v< TakeAdapter > &&noexcept(++std::declval< TakeAdapter & >()))
 
constexpr value_type operator* () const noexcept(noexcept(*std::declval< const Iter & >()))
 
constexpr bool operator== (const TakeAdapter &other) const noexcept(noexcept(std::declval< const Iter & >()==std::declval< const Iter & >()))
 
constexpr bool operator!= (const TakeAdapter &other) const noexcept(noexcept(std::declval< const TakeAdapter & >()==std::declval< const TakeAdapter & >()))
 
constexpr bool IsAtEnd () const noexcept(noexcept(std::declval< const Iter & >()==std::declval< const Iter & >()))
 Checks if the iterator has reached the end.
 
constexpr TakeAdapter begin () const noexcept(std::is_nothrow_copy_constructible_v< TakeAdapter >)
 
constexpr TakeAdapter end () const noexcept(std::is_nothrow_copy_constructible_v< TakeAdapter >)
 
- Public Member Functions inherited from helios::utils::FunctionalAdapterBase< TakeAdapter< Iter > >
constexpr auto Filter (Pred predicate) const noexcept(noexcept(FilterAdapter< TakeAdapter< Iter >, 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< TakeAdapter< Iter >, 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< TakeAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), count)))
 Limits the number of elements to at most count.
 
constexpr auto Skip (size_t count) const noexcept(noexcept(SkipAdapter< TakeAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), count)))
 Skips the first count elements.
 
constexpr auto TakeWhile (Pred predicate) const noexcept(noexcept(TakeWhileAdapter< TakeAdapter< Iter >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Takes elements while a predicate is true.
 
constexpr auto SkipWhile (Pred predicate) const noexcept(noexcept(SkipWhileAdapter< TakeAdapter< Iter >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Skips elements while a predicate is true.
 
constexpr auto Enumerate () const noexcept(noexcept(EnumerateAdapter< TakeAdapter< Iter > >(GetDerived().begin(), GetDerived().end())))
 Adds an index to each element.
 
constexpr auto Inspect (Func inspector) const noexcept(noexcept(InspectAdapter< TakeAdapter< Iter >, Func >(GetDerived().begin(), GetDerived().end(), std::move(inspector))))
 Observes each element without modifying it.
 
constexpr auto StepBy (size_t step) const noexcept(noexcept(StepByAdapter< TakeAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), step)))
 Takes every Nth element.
 
constexpr auto Chain (OtherIter begin, OtherIter end) const noexcept(noexcept(ChainAdapter< TakeAdapter< Iter >, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Chains another range after this one.
 
constexpr auto Chain (R &range) const noexcept(noexcept(ChainAdapterFromRange(GetDerived(), range)))
 Chains another range after this one.
 
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< TakeAdapter< Iter > >(GetDerived().begin(), GetDerived().end())))
 Reverses the order of elements.
 
constexpr auto Slide (size_t window_size) const noexcept(noexcept(SlideAdapter< TakeAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), window_size)))
 Creates sliding windows over elements.
 
constexpr auto Stride (size_t stride) const noexcept(noexcept(StrideAdapter< TakeAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), stride)))
 Takes every Nth element with stride.
 
constexpr auto Zip (OtherIter begin, OtherIter end) const noexcept(noexcept(ZipAdapter< TakeAdapter< Iter >, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Zips another range with this one.
 
constexpr auto Zip (R &range) const noexcept(noexcept(ZipAdapterFromRange(GetDerived(), range)))
 Zips another range with this one.
 
constexpr auto Zip (const R &range) const noexcept(noexcept(ZipAdapterFromRange(GetDerived(), range)))
 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 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.
 
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 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 Collect () const
 Terminal operation: collects all elements into a vector.
 
constexpr void Into (OutIt out) const
 

Additional Inherited Members

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

Detailed Description

template<typename Iter>
requires TakeAdapterRequirements<Iter>
class helios::utils::TakeAdapter< Iter >

Definition at line 662 of file functional_adapters.hpp.

Member Typedef Documentation

◆ difference_type

template<typename Iter >
using helios::utils::TakeAdapter< Iter >::difference_type = std::iter_difference_t<Iter>

◆ iterator_category

template<typename Iter >
using helios::utils::TakeAdapter< Iter >::iterator_category = std::forward_iterator_tag

◆ pointer

◆ reference

◆ value_type

template<typename Iter >
using helios::utils::TakeAdapter< Iter >::value_type = std::iter_value_t<Iter>

Constructor & Destructor Documentation

◆ TakeAdapter() [1/3]

template<typename Iter >
constexpr helios::utils::TakeAdapter< Iter >::TakeAdapter ( Iter  begin,
Iter  end,
size_t  count 
)
inlineconstexprnoexcept

Constructs a take adapter with the given iterator range and count.

Parameters
beginStart of the iterator range
endEnd of the iterator range
countMaximum number of elements to yield

Definition at line 676 of file functional_adapters.hpp.

678 : begin_(std::move(begin)), current_(begin_), end_(std::move(end)), initial_count_(count), remaining_(count) {}
constexpr TakeAdapter end() const noexcept(std::is_nothrow_copy_constructible_v< TakeAdapter >)
constexpr TakeAdapter begin() const noexcept(std::is_nothrow_copy_constructible_v< TakeAdapter >)

◆ TakeAdapter() [2/3]

template<typename Iter >
constexpr helios::utils::TakeAdapter< Iter >::TakeAdapter ( const TakeAdapter< Iter > &  ) const
constexprdefaultnoexcept

◆ TakeAdapter() [3/3]

template<typename Iter >
constexpr helios::utils::TakeAdapter< Iter >::TakeAdapter ( TakeAdapter< Iter > &&  ) const
constexprdefaultnoexcept

◆ ~TakeAdapter()

Member Function Documentation

◆ begin()

template<typename Iter >
constexpr TakeAdapter helios::utils::TakeAdapter< Iter >::begin ( ) const
inlineconstexprnoexcept

◆ end()

template<typename Iter >
requires TakeAdapterRequirements<Iter>
constexpr auto helios::utils::TakeAdapter< Iter >::end ( ) const
constexprnoexcept
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 762 of file functional_adapters.hpp.

763 {
764 auto end_iter = *this;
765 end_iter.remaining_ = 0;
766 return end_iter;
767}

◆ IsAtEnd()

template<typename Iter >
constexpr bool helios::utils::TakeAdapter< Iter >::IsAtEnd ( ) const
inlineconstexprnoexcept

Checks if the iterator has reached the end.

Returns
True if at end, false otherwise
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 707 of file functional_adapters.hpp.

708 {
709 return remaining_ == 0 || current_ == end_;
710 }

◆ operator!=()

template<typename Iter >
constexpr bool helios::utils::TakeAdapter< Iter >::operator!= ( const TakeAdapter< Iter > &  other) const
inlineconstexprnoexcept

◆ operator*()

template<typename Iter >
constexpr value_type helios::utils::TakeAdapter< Iter >::operator* ( ) const
inlineconstexprnoexcept

◆ operator++() [1/2]

template<typename Iter >
requires TakeAdapterRequirements<Iter>
constexpr auto helios::utils::TakeAdapter< Iter >::operator++ ( )
constexprnoexcept
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 728 of file functional_adapters.hpp.

728 {
729 if (remaining_ > 0 && current_ != end_) {
730 ++current_;
731 --remaining_;
732 }
733 return *this;
734}

◆ operator++() [2/2]

template<typename Iter >
requires TakeAdapterRequirements<Iter>
constexpr auto helios::utils::TakeAdapter< Iter >::operator++ ( int  )
constexprnoexcept

Definition at line 738 of file functional_adapters.hpp.

739 {
740 auto temp = *this;
741 ++(*this);
742 return temp;
743}

◆ operator=() [1/2]

template<typename Iter >
constexpr TakeAdapter & helios::utils::TakeAdapter< Iter >::operator= ( const TakeAdapter< Iter > &  )
constexprdefaultnoexcept

◆ operator=() [2/2]

template<typename Iter >
constexpr TakeAdapter & helios::utils::TakeAdapter< Iter >::operator= ( TakeAdapter< Iter > &&  )
constexprdefaultnoexcept

◆ operator==()

template<typename Iter >
requires TakeAdapterRequirements<Iter>
constexpr bool helios::utils::TakeAdapter< Iter >::operator== ( const TakeAdapter< Iter > &  other) const
constexprnoexcept
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 747 of file functional_adapters.hpp.

748 {
749 // Both are at end if either has no remaining elements or both iterators are at end
750 const bool this_at_end = (remaining_ == 0) || (current_ == end_);
751 const bool other_at_end = (other.remaining_ == 0) || (other.current_ == other.end_);
752
753 if (this_at_end && other_at_end) {
754 return true;
755 }
756
757 return (current_ == other.current_) && (remaining_ == other.remaining_);
758}