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

#include <functional_adapters.hpp>

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

Public Types

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

Public Member Functions

constexpr SlideAdapter (Iter begin, Iter end, size_t window_size) noexcept(std::is_nothrow_move_constructible_v< Iter > &&std::is_nothrow_copy_constructible_v< Iter > &&noexcept(std::declval< Iter & >() !=std::declval< Iter & >()) &&noexcept(++std::declval< Iter & >()))
 Constructs a slide adapter.
 
constexpr SlideAdapter (const SlideAdapter &) noexcept(std::is_nothrow_copy_constructible_v< Iter >)=default
 
constexpr SlideAdapter (SlideAdapter &&) noexcept(std::is_nothrow_move_constructible_v< Iter >)=default
 
constexpr ~SlideAdapter () noexcept(std::is_nothrow_destructible_v< Iter >)=default
 
constexpr SlideAdapteroperator= (const SlideAdapter &) noexcept(std::is_nothrow_copy_assignable_v< Iter >)=default
 
constexpr SlideAdapteroperator= (SlideAdapter &&) noexcept(std::is_nothrow_move_assignable_v< Iter >)=default
 
constexpr SlideAdapteroperator++ () noexcept(noexcept(std::declval< Iter & >() !=std::declval< Iter & >()) &&noexcept(++std::declval< Iter & >()))
 
constexpr SlideAdapter operator++ (int) noexcept(std::is_nothrow_copy_constructible_v< SlideAdapter > &&noexcept(++std::declval< SlideAdapter & >()))
 
constexpr value_type operator* () const noexcept(std::is_nothrow_constructible_v< SlideView< Iter >, Iter, size_t >)
 Dereferences the iterator to get the current window.
 
constexpr bool operator== (const SlideAdapter &other) const noexcept(noexcept(std::declval< const Iter & >()==std::declval< const Iter & >()))
 
constexpr bool operator!= (const SlideAdapter &other) const noexcept(noexcept(std::declval< const Iter & >() !=std::declval< const Iter & >()))
 
constexpr SlideAdapter begin () const noexcept(std::is_nothrow_constructible_v< SlideAdapter, const Iter &, const Iter &, size_t >)
 
constexpr SlideAdapter end () const noexcept(std::is_nothrow_copy_constructible_v< SlideAdapter > &&std::is_nothrow_copy_assignable_v< Iter > &&noexcept(std::declval< Iter & >() !=std::declval< const Iter & >()) &&noexcept(++std::declval< Iter & >()))
 
constexpr size_t WindowSize () const noexcept
 Returns the window size.
 
- Public Member Functions inherited from helios::utils::FunctionalAdapterBase< SlideAdapter< Iter > >
constexpr auto Filter (Pred predicate) const noexcept(noexcept(FilterAdapter< SlideAdapter< 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< SlideAdapter< 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< SlideAdapter< 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< SlideAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), count)))
 Skips the first count elements.
 
constexpr auto TakeWhile (Pred predicate) const noexcept(noexcept(TakeWhileAdapter< SlideAdapter< 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< SlideAdapter< Iter >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Skips elements while a predicate is true.
 
constexpr auto Enumerate () const noexcept(noexcept(EnumerateAdapter< SlideAdapter< Iter > >(GetDerived().begin(), GetDerived().end())))
 Adds an index to each element.
 
constexpr auto Inspect (Func inspector) const noexcept(noexcept(InspectAdapter< SlideAdapter< 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< SlideAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), step)))
 Takes every Nth element.
 
constexpr auto Chain (OtherIter begin, OtherIter end) const noexcept(noexcept(ChainAdapter< SlideAdapter< 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< SlideAdapter< Iter > >(GetDerived().begin(), GetDerived().end())))
 Reverses the order of elements.
 
constexpr auto Slide (size_t window_size) const noexcept(noexcept(SlideAdapter< SlideAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), window_size)))
 Creates sliding windows over elements.
 
constexpr auto Stride (size_t stride) const noexcept(noexcept(StrideAdapter< SlideAdapter< Iter > >(GetDerived().begin(), GetDerived().end(), stride)))
 Takes every Nth element with stride.
 
constexpr auto Zip (OtherIter begin, OtherIter end) const noexcept(noexcept(ZipAdapter< SlideAdapter< 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< SlideAdapter< Iter > >
constexpr SlideAdapter< Iter > & GetDerived () noexcept
 Gets reference to derived class instance.
 
constexpr const SlideAdapter< Iter > & GetDerived () const noexcept
 Gets const reference to derived class instance.
 

Detailed Description

template<typename Iter>
requires SlideAdapterRequirements<Iter>
class helios::utils::SlideAdapter< Iter >

Definition at line 2139 of file functional_adapters.hpp.

Member Typedef Documentation

◆ difference_type

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

◆ iterator_category

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

◆ pointer

◆ reference

◆ value_type

Constructor & Destructor Documentation

◆ SlideAdapter() [1/3]

template<typename Iter >
requires SlideAdapterRequirements<Iter>
constexpr helios::utils::SlideAdapter< Iter >::SlideAdapter ( Iter  begin,
Iter  end,
size_t  window_size 
)
constexprnoexcept

Constructs a slide adapter.

Warning
window_size must be greater than 0
Parameters
beginIterator to the beginning of the range
endIterator to the end of the range
window_sizeSize of the sliding window
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2214 of file functional_adapters.hpp.

2217 : begin_(std::move(begin)), current_(begin_), end_(std::move(end)), window_size_(window_size) {
2218 // If we can't form a complete window, start at end
2219 Iter iter = begin_;
2220 size_t count = 0;
2221 while (iter != end_) {
2222 ++iter;
2223 ++count;
2224 }
2225 if (count < window_size_) {
2226 current_ = end_;
2227 }
2228}
constexpr SlideAdapter end() const noexcept(std::is_nothrow_copy_constructible_v< SlideAdapter > &&std::is_nothrow_copy_assignable_v< Iter > &&noexcept(std::declval< Iter & >() !=std::declval< const Iter & >()) &&noexcept(++std::declval< Iter & >()))
constexpr SlideAdapter begin() const noexcept(std::is_nothrow_constructible_v< SlideAdapter, const Iter &, const Iter &, size_t >)

◆ SlideAdapter() [2/3]

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

◆ SlideAdapter() [3/3]

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

◆ ~SlideAdapter()

Member Function Documentation

◆ begin()

template<typename Iter >
constexpr SlideAdapter helios::utils::SlideAdapter< Iter >::begin ( ) const
inlineconstexprnoexcept
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2190 of file functional_adapters.hpp.

2191 {
2192 return {begin_, end_, window_size_};
2193 }

◆ end()

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

Definition at line 2251 of file functional_adapters.hpp.

2254 {
2255 auto result = *this;
2256
2257 // Calculate end position: when we can't form a complete window
2258 Iter iter = begin_;
2259 size_t count = 0;
2260 while (iter != end_) {
2261 ++iter;
2262 ++count;
2263 }
2264
2265 // Position where we can't form more windows
2266 if (count >= window_size_) {
2267 result.current_ = begin_;
2268 for (size_t i = 0; i < count - window_size_ + 1; ++i) {
2269 ++result.current_;
2270 }
2271 } else {
2272 result.current_ = end_;
2273 }
2274
2275 return result;
2276}

◆ operator!=()

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

Definition at line 2185 of file functional_adapters.hpp.

2186 {
2187 return current_ != other.current_;
2188 }

◆ operator*()

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

Dereferences the iterator to get the current window.

Returns
SlideView representing the current window
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2175 of file functional_adapters.hpp.

2176 {
2177 return {current_, window_size_};
2178 }

◆ operator++() [1/2]

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

Definition at line 2232 of file functional_adapters.hpp.

2233 {
2234 if (current_ != end_) {
2235 ++current_;
2236 }
2237 return *this;
2238}

◆ operator++() [2/2]

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

Definition at line 2242 of file functional_adapters.hpp.

2243 {
2244 auto temp = *this;
2245 ++(*this);
2246 return temp;
2247}

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==()

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

Definition at line 2180 of file functional_adapters.hpp.

2181 {
2182 return current_ == other.current_;
2183 }

◆ WindowSize()

template<typename Iter >
constexpr size_t helios::utils::SlideAdapter< Iter >::WindowSize ( ) const
inlineconstexprnoexcept

Returns the window size.

Returns
Size of the sliding window
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/utils/functional_adapters.hpp.

Definition at line 2203 of file functional_adapters.hpp.

2203{ return window_size_; }