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

Adapter that yields sliding windows of elements. More...

#include <functional_adapters.hpp>

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

Public Types

using iterator_concept = std::forward_iterator_tag
using iterator_category = std::input_iterator_tag
using value_type = SlideView<Iter>
using reference = value_type
using pointer = void
using difference_type = std::iter_difference_t<Iter>

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.
template<ExternalRange R>
requires SlideAdapterRequirements<std::ranges::iterator_t<R>>
constexpr SlideAdapter (R &range, size_t window_size) noexcept(noexcept(SlideAdapter(std::ranges::begin(range), std::ranges::end(range), window_size)))
 Constructs a slide adapter from a range.
template<ExternalRange R>
requires SlideAdapterRequirements<std::ranges::iterator_t<const R>>
constexpr SlideAdapter (const R &range, size_t window_size) noexcept(noexcept(SlideAdapter(std::ranges::cbegin(range), std::ranges::cend(range), window_size)))
 Constructs a slide adapter from a const range.
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 reference operator* () const noexcept(std::is_nothrow_constructible_v< SlideView< Iter >, Iter, size_t >)
 Dereferences the iterator to get the current window.
pointer operator-> () const =delete
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 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< Derived >(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 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< SlideAdapter< Iter > >
constexpr SlideAdapter< Iter > & GetDerived () noexcept
 Gets reference to derived class instance.

Detailed Description

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

Adapter that yields sliding windows of elements.

Creates overlapping windows of a fixed size, moving one element at a time. Each window is returned as a SlideView, which is a non-allocating view over the elements.

Template Parameters
IterType of the underlying iterator
std::vector<int> data = {1, 2, 3, 4, 5};
auto slide = SlideAdapterFromRange(data, 3);
// Iterate over windows
for (const auto& window : slide) {
// Each window is a SlideView
for (int val : window) {
std::cout << val << " ";
}
std::cout << "\n";
}
// Collect windows if needed
auto windows = slide.Collect(); // Vector of SlideViews
// Convert a window to vector if ownership needed
auto first_window = (*slide.begin()).Collect(); // std::vector<int>

Definition at line 3005 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>

Definition at line 3012 of file functional_adapters.hpp.

◆ iterator_category

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

Definition at line 3008 of file functional_adapters.hpp.

◆ iterator_concept

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

Definition at line 3007 of file functional_adapters.hpp.

◆ pointer

template<typename Iter>
using helios::utils::SlideAdapter< Iter >::pointer = void

Definition at line 3011 of file functional_adapters.hpp.

◆ reference

template<typename Iter>
using helios::utils::SlideAdapter< Iter >::reference = value_type

Definition at line 3010 of file functional_adapters.hpp.

◆ value_type

template<typename Iter>
using helios::utils::SlideAdapter< Iter >::value_type = SlideView<Iter>

Definition at line 3009 of file functional_adapters.hpp.

Constructor & Destructor Documentation

◆ SlideAdapter() [1/5]

template<typename Iter>
requires SlideAdapterRequirements<Iter>
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

Definition at line 3135 of file functional_adapters.hpp.

◆ SlideAdapter() [2/5]

template<typename Iter>
template<ExternalRange R>
requires SlideAdapterRequirements<std::ranges::iterator_t<R>>
helios::utils::SlideAdapter< Iter >::SlideAdapter ( R & range,
size_t window_size )
inlineexplicitconstexprnoexcept

Constructs a slide adapter from a range.

Template Parameters
RThe type of the range
Parameters
rangeThe range to adapt
window_sizeThe size of the sliding window

Definition at line 3035 of file functional_adapters.hpp.

◆ SlideAdapter() [3/5]

template<typename Iter>
template<ExternalRange R>
requires SlideAdapterRequirements<std::ranges::iterator_t<const R>>
helios::utils::SlideAdapter< Iter >::SlideAdapter ( const R & range,
size_t window_size )
inlineexplicitconstexprnoexcept

Constructs a slide adapter from a const range.

Template Parameters
RThe type of the range
Parameters
rangeThe range to adapt
window_sizeThe size of the sliding window

Definition at line 3049 of file functional_adapters.hpp.

◆ SlideAdapter() [4/5]

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

◆ SlideAdapter() [5/5]

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

◆ ~SlideAdapter()

template<typename Iter>
helios::utils::SlideAdapter< Iter >::~SlideAdapter ( )
constexprdefaultnoexcept

Member Function Documentation

◆ begin()

template<typename Iter>
SlideAdapter helios::utils::SlideAdapter< Iter >::begin ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 3097 of file functional_adapters.hpp.

◆ end()

template<typename Iter>
requires SlideAdapterRequirements<Iter>
auto helios::utils::SlideAdapter< Iter >::end ( ) const
nodiscardconstexprnoexcept

Definition at line 3181 of file functional_adapters.hpp.

◆ operator!=()

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

Definition at line 3091 of file functional_adapters.hpp.

◆ operator*()

template<typename Iter>
reference helios::utils::SlideAdapter< Iter >::operator* ( ) const
inlinenodiscardconstexprnoexcept

Dereferences the iterator to get the current window.

Returns
SlideView representing the current window

Definition at line 3078 of file functional_adapters.hpp.

◆ operator++() [1/2]

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

Definition at line 3160 of file functional_adapters.hpp.

◆ operator++() [2/2]

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

Definition at line 3171 of file functional_adapters.hpp.

◆ operator->()

template<typename Iter>
pointer helios::utils::SlideAdapter< Iter >::operator-> ( ) const
delete

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==()

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

Definition at line 3085 of file functional_adapters.hpp.

◆ WindowSize()

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

Returns the window size.

Returns
Size of the sliding window

Definition at line 3113 of file functional_adapters.hpp.