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

Iterator adapter that applies a function to each element for observation. More...

#include <functional_adapters.hpp>

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

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

Detailed Description

template<typename Iter, typename Func>
requires InspectAdapterRequirements<Iter, Func>
class helios::utils::InspectAdapter< Iter, Func >

Iterator adapter that applies a function to each element for observation.

This adapter allows observing elements without modifying them. The inspector function is called for side effects only.

Template Parameters
IterUnderlying iterator type
FuncInspector function type
// Inspect entities to log their IDs
auto inspected = query.Inspect([](const Entity& e) { helios::log::Info("{}",
e.id);
});
void Info(std::string_view message) noexcept
Logs an info message with the default logger.
Definition logger.hpp:483

Definition at line 1742 of file functional_adapters.hpp.

Member Typedef Documentation

◆ difference_type

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

Definition at line 1750 of file functional_adapters.hpp.

◆ iterator_category

template<typename Iter, typename Func>
using helios::utils::InspectAdapter< Iter, Func >::iterator_category = details::adapter_iterator_category_t<Iter>

Definition at line 1746 of file functional_adapters.hpp.

◆ iterator_concept

template<typename Iter, typename Func>
using helios::utils::InspectAdapter< Iter, Func >::iterator_concept = details::adapter_iterator_concept_t<Iter>

Definition at line 1745 of file functional_adapters.hpp.

◆ pointer

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

Definition at line 1749 of file functional_adapters.hpp.

◆ reference

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

Definition at line 1748 of file functional_adapters.hpp.

◆ value_type

template<typename Iter, typename Func>
using helios::utils::InspectAdapter< Iter, Func >::value_type = std::iter_value_t<Iter>

Definition at line 1747 of file functional_adapters.hpp.

Constructor & Destructor Documentation

◆ InspectAdapter() [1/5]

template<typename Iter, typename Func>
helios::utils::InspectAdapter< Iter, Func >::InspectAdapter ( Iter begin,
Iter end,
Func inspector )
inlineconstexprnoexcept

Constructs an inspect adapter with the given iterator range and inspector function.

Parameters
beginStart of the iterator range
endEnd of the iterator range
inspectorFunction to call for each element

Definition at line 1759 of file functional_adapters.hpp.

◆ InspectAdapter() [2/5]

template<typename Iter, typename Func>
template<ExternalRange R>
requires InspectAdapterRequirements<std::ranges::iterator_t<R>, Func>
helios::utils::InspectAdapter< Iter, Func >::InspectAdapter ( R & range,
Func inspector )
inlineconstexprnoexcept

Constructs an inspect adapter with the given range and inspector function.

Template Parameters
RThe type of the input range
Parameters
rangeThe input range to adapt
inspectorFunction to call for each element

Definition at line 1777 of file functional_adapters.hpp.

◆ InspectAdapter() [3/5]

template<typename Iter, typename Func>
template<ExternalRange R>
requires InspectAdapterRequirements<std::ranges::iterator_t<const R>, Func>
helios::utils::InspectAdapter< Iter, Func >::InspectAdapter ( const R & range,
Func inspector )
inlineconstexprnoexcept

Constructs an inspect adapter with the given const range and inspector function.

Template Parameters
RThe type of the input range
Parameters
rangeThe input range to adapt
inspectorFunction to call for each element

Definition at line 1792 of file functional_adapters.hpp.

◆ InspectAdapter() [4/5]

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

◆ InspectAdapter() [5/5]

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

◆ ~InspectAdapter()

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

Member Function Documentation

◆ begin()

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

Definition at line 1839 of file functional_adapters.hpp.

◆ end()

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

Definition at line 1844 of file functional_adapters.hpp.

◆ operator!=()

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

Definition at line 1833 of file functional_adapters.hpp.

◆ operator*()

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

Definition at line 1884 of file functional_adapters.hpp.

◆ operator++() [1/2]

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

Definition at line 1866 of file functional_adapters.hpp.

◆ operator++() [2/2]

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

Definition at line 1874 of file functional_adapters.hpp.

◆ operator->()

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==()

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

Definition at line 1827 of file functional_adapters.hpp.