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

Iterator adapter that transforms each element using a function. More...

#include <functional_adapters.hpp>

Inheritance diagram for helios::utils::MapAdapter< Iter, Func >:
helios::utils::FunctionalAdapterBase< MapAdapter< Iter, Func > >

Public Types

using iterator_concept = std::input_iterator_tag
using iterator_category = std::input_iterator_tag
using value_type = typename DeduceValueType<std::iter_value_t<Iter>>::Type
using reference = value_type
using pointer = void
using difference_type = std::iter_difference_t<Iter>

Public Member Functions

constexpr MapAdapter (Iter begin, Iter end, Func transform) noexcept(std::is_nothrow_move_constructible_v< Iter > &&std::is_nothrow_move_constructible_v< Func >)
 Constructs a map adapter with the given iterator range and transform function.
template<ExternalRange R>
requires MapAdapterRequirements<std::ranges::iterator_t<R>, Func>
constexpr MapAdapter (R &range, Func transform) noexcept(noexcept(MapAdapter(std::ranges::begin(range), std::ranges::end(range), std::move(transform))))
 Constructs a map adapter from a range and transform function.
template<ExternalRange R>
requires MapAdapterRequirements<std::ranges::iterator_t<const R>, Func>
constexpr MapAdapter (const R &range, Func transform) noexcept(noexcept(MapAdapter(std::ranges::cbegin(range), std::ranges::cend(range), std::move(transform))))
 Constructs a map adapter from a const range and transform function.
constexpr MapAdapter (const MapAdapter &) noexcept(std::is_nothrow_copy_constructible_v< Iter > &&std::is_nothrow_copy_constructible_v< Func >)=default
constexpr MapAdapter (MapAdapter &&) noexcept(std::is_nothrow_move_constructible_v< Iter > &&std::is_nothrow_move_constructible_v< Func >)=default
constexpr ~MapAdapter () noexcept(std::is_nothrow_destructible_v< Iter > &&std::is_nothrow_destructible_v< Func >)=default
constexpr MapAdapteroperator= (const MapAdapter &) noexcept(std::is_nothrow_copy_assignable_v< Iter > &&std::is_nothrow_copy_assignable_v< Func >)=default
constexpr MapAdapteroperator= (MapAdapter &&) noexcept(std::is_nothrow_move_assignable_v< Iter > &&std::is_nothrow_move_assignable_v< Func >)=default
constexpr MapAdapteroperator++ () noexcept(noexcept(++std::declval< Iter & >()))
constexpr MapAdapter operator++ (int) noexcept(std::is_nothrow_copy_constructible_v< MapAdapter > &&noexcept(++std::declval< MapAdapter & >()))
constexpr reference operator* () const noexcept(std::is_nothrow_invocable_v< Func, std::iter_value_t< Iter > > &&noexcept(*std::declval< const Iter & >()))
pointer operator-> () const =delete
constexpr bool operator== (const MapAdapter &other) const noexcept(noexcept(std::declval< const Iter & >()==std::declval< const Iter & >()))
constexpr bool operator!= (const MapAdapter &other) const noexcept(noexcept(std::declval< const MapAdapter & >()==std::declval< const MapAdapter & >()))
constexpr MapAdapter begin () const noexcept(std::is_nothrow_copy_constructible_v< MapAdapter >)
constexpr MapAdapter end () const noexcept(std::is_nothrow_constructible_v< MapAdapter, const Iter &, const Iter &, const Func & >)
Public Member Functions inherited from helios::utils::FunctionalAdapterBase< MapAdapter< Iter, Func > >
constexpr auto Filter (Pred predicate) const noexcept(noexcept(FilterAdapter< MapAdapter< Iter, Func >, 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< 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< MapAdapter< Iter, Func > >(GetDerived().begin(), GetDerived().end(), count)))
 Limits the number of elements to at most count.
constexpr auto Skip (size_t count) const noexcept(noexcept(SkipAdapter< MapAdapter< Iter, Func > >(GetDerived().begin(), GetDerived().end(), count)))
 Skips the first count elements.
constexpr auto TakeWhile (Pred predicate) const noexcept(noexcept(TakeWhileAdapter< MapAdapter< Iter, Func >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Takes elements while a predicate is true.
constexpr auto SkipWhile (Pred predicate) const noexcept(noexcept(SkipWhileAdapter< MapAdapter< Iter, Func >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Skips elements while a predicate is true.
constexpr auto Enumerate () const noexcept(noexcept(EnumerateAdapter< MapAdapter< Iter, Func > >(GetDerived().begin(), GetDerived().end())))
 Adds an index to each element.
constexpr auto Inspect (Func inspector) const noexcept(noexcept(InspectAdapter< MapAdapter< Iter, Func >, Func >(GetDerived().begin(), GetDerived().end(), std::move(inspector))))
 Observes each element without modifying it.
constexpr auto StepBy (size_t step) const noexcept(noexcept(StepByAdapter< MapAdapter< Iter, Func > >(GetDerived().begin(), GetDerived().end(), step)))
 Takes every Nth element.
constexpr auto Chain (OtherIter begin, OtherIter end) const noexcept(noexcept(ChainAdapter< MapAdapter< Iter, Func >, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Chains another range after this one.
constexpr auto Reverse () const noexcept(noexcept(ReverseAdapter< MapAdapter< Iter, Func > >(GetDerived().begin(), GetDerived().end())))
 Reverses the order of elements.
constexpr auto Slide (size_t window_size) const noexcept(noexcept(SlideAdapter< MapAdapter< Iter, Func > >(GetDerived().begin(), GetDerived().end(), window_size)))
 Creates sliding windows over elements.
constexpr auto Stride (size_t stride) const noexcept(noexcept(StrideAdapter< MapAdapter< Iter, Func > >(GetDerived().begin(), GetDerived().end(), stride)))
 Takes every Nth element with stride.
constexpr auto Zip (OtherIter begin, OtherIter end) const noexcept(noexcept(ZipAdapter< MapAdapter< Iter, Func >, 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< MapAdapter< Iter, Func > >
constexpr MapAdapter< Iter, Func > & GetDerived () noexcept
 Gets reference to derived class instance.

Detailed Description

template<typename Iter, typename Func>
requires MapAdapterRequirements<Iter, Func>
class helios::utils::MapAdapter< Iter, Func >

Iterator adapter that transforms each element using a function.

This adapter applies a transformation function to each element during iteration. The transformation is lazy - it happens when the element is accessed, not when the adapter is created.

The transformation function can accept either the full value or individual tuple components if the value is a tuple type.

Note
This adapter maintains forward iterator semantics. The adapter is constexpr-compatible for compile-time evaluation.
Template Parameters
IterUnderlying iterator type that satisfies IteratorLike concept
FuncTransformation function type
auto positions = query.Map([](const Transform& t) {
return t.position;
});

Definition at line 676 of file functional_adapters.hpp.

Member Typedef Documentation

◆ difference_type

template<typename Iter, typename Func>
using helios::utils::MapAdapter< Iter, Func >::difference_type = std::iter_difference_t<Iter>

Definition at line 699 of file functional_adapters.hpp.

◆ iterator_category

template<typename Iter, typename Func>
using helios::utils::MapAdapter< Iter, Func >::iterator_category = std::input_iterator_tag

Definition at line 695 of file functional_adapters.hpp.

◆ iterator_concept

template<typename Iter, typename Func>
using helios::utils::MapAdapter< Iter, Func >::iterator_concept = std::input_iterator_tag

Definition at line 694 of file functional_adapters.hpp.

◆ pointer

template<typename Iter, typename Func>
using helios::utils::MapAdapter< Iter, Func >::pointer = void

Definition at line 698 of file functional_adapters.hpp.

◆ reference

template<typename Iter, typename Func>
using helios::utils::MapAdapter< Iter, Func >::reference = value_type

Definition at line 697 of file functional_adapters.hpp.

◆ value_type

template<typename Iter, typename Func>
using helios::utils::MapAdapter< Iter, Func >::value_type = typename DeduceValueType<std::iter_value_t<Iter>>::Type

Definition at line 696 of file functional_adapters.hpp.

Constructor & Destructor Documentation

◆ MapAdapter() [1/5]

template<typename Iter, typename Func>
helios::utils::MapAdapter< Iter, Func >::MapAdapter ( Iter begin,
Iter end,
Func transform )
inlineconstexprnoexcept

Constructs a map adapter with the given iterator range and transform function.

Parameters
beginStart of the iterator range
endEnd of the iterator range
transformFunction to transform elements

Definition at line 708 of file functional_adapters.hpp.

◆ MapAdapter() [2/5]

template<typename Iter, typename Func>
template<ExternalRange R>
requires MapAdapterRequirements<std::ranges::iterator_t<R>, Func>
helios::utils::MapAdapter< Iter, Func >::MapAdapter ( R & range,
Func transform )
inlineconstexprnoexcept

Constructs a map adapter from a range and transform function.

Template Parameters
RThe type of the input range
Parameters
rangeThe input range to adapt
transformFunction to transform elements

Definition at line 724 of file functional_adapters.hpp.

◆ MapAdapter() [3/5]

template<typename Iter, typename Func>
template<ExternalRange R>
requires MapAdapterRequirements<std::ranges::iterator_t<const R>, Func>
helios::utils::MapAdapter< Iter, Func >::MapAdapter ( const R & range,
Func transform )
inlineconstexprnoexcept

Constructs a map adapter from a const range and transform function.

Template Parameters
RThe type of the input range
Parameters
rangeThe input range to adapt
transformFunction to transform elements

Definition at line 738 of file functional_adapters.hpp.

◆ MapAdapter() [4/5]

template<typename Iter, typename Func>
helios::utils::MapAdapter< Iter, Func >::MapAdapter ( const MapAdapter< Iter, Func > & ) const &&
constexprdefaultnoexcept

◆ MapAdapter() [5/5]

template<typename Iter, typename Func>
helios::utils::MapAdapter< Iter, Func >::MapAdapter ( MapAdapter< Iter, Func > && ) const &&
constexprdefaultnoexcept

◆ ~MapAdapter()

template<typename Iter, typename Func>
helios::utils::MapAdapter< Iter, Func >::~MapAdapter ( ) &&
constexprdefaultnoexcept

Member Function Documentation

◆ begin()

template<typename Iter, typename Func>
MapAdapter helios::utils::MapAdapter< Iter, Func >::begin ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 784 of file functional_adapters.hpp.

◆ end()

template<typename Iter, typename Func>
MapAdapter helios::utils::MapAdapter< Iter, Func >::end ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 789 of file functional_adapters.hpp.

◆ operator!=()

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

Definition at line 778 of file functional_adapters.hpp.

◆ operator*()

template<typename Iter, typename Func>
requires MapAdapterRequirements<Iter, Func>
auto helios::utils::MapAdapter< Iter, Func >::operator* ( ) const
nodiscardconstexprnoexcept

Definition at line 829 of file functional_adapters.hpp.

◆ operator++() [1/2]

template<typename Iter, typename Func>
requires MapAdapterRequirements<Iter, Func>
auto helios::utils::MapAdapter< Iter, Func >::operator++ ( )
constexprnoexcept

Definition at line 811 of file functional_adapters.hpp.

◆ operator++() [2/2]

template<typename Iter, typename Func>
requires MapAdapterRequirements<Iter, Func>
auto helios::utils::MapAdapter< Iter, Func >::operator++ ( int )
nodiscardconstexprnoexcept

Definition at line 819 of file functional_adapters.hpp.

◆ operator->()

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

template<typename Iter, typename Func>
MapAdapter & helios::utils::MapAdapter< Iter, Func >::operator= ( MapAdapter< Iter, Func > && ) &&
constexprdefaultnoexcept

◆ operator==()

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

Definition at line 773 of file functional_adapters.hpp.