EmrysFilter 0.1.0
State estimation utilities in C++23 using Eigen
Loading...
Searching...
No Matches
Emrys::upkeep::When< Predicate, Actions > Struct Template Reference

Trigger that runs its actions when its predicate holds for the state: the general trigger, of which WhenEss and WhenSize are two. More...

#include <EmrysFilter/Distributions/Upkeep.h>

Public Member Functions

 When (Predicate test, Actions... toRun)
 Runs toRun, in order, when test holds for the state.
template<typename State>
requires internal::UpkeepTest<Predicate, State const &> && (UpkeepOperation<Actions, State> && ...)
std::expected< bool, WeightError > operator() (State &state) const
 Tests state and runs the actions on it if the test holds.

Public Attributes

Predicate predicate
 the test of the state
std::tuple< Actions... > actions
 run in order when the test holds

Detailed Description

template<typename Predicate, typename... Actions>
struct Emrys::upkeep::When< Predicate, Actions >

Trigger that runs its actions when its predicate holds for the state: the general trigger, of which WhenEss and WhenSize are two.

The predicate is called with the state, as a const reference, and returns a bool, or an std::expected<bool, WeightError> for a test that can fail, whose error the trigger returns without running anything. The actions are called with the state alone, in order, and stop at the first error, which the trigger returns; actions that ran before it keep their effect.

auto const refine = upkeep::when([](auto const & grid) { return grid.size() < 64; }, upkeep::subdivide(2));
refine(filter.state());
constexpr Subdivide subdivide(std::ptrdiff_t factor=2)
Definition Upkeep.h:1071
When< Predicate, Actions... > when(Predicate predicate, Actions... actions)
Definition Upkeep.h:762

Member Function Documentation

◆ operator()()

template<typename Predicate, typename... Actions>
template<typename State>
requires internal::UpkeepTest<Predicate, State const &> && (UpkeepOperation<Actions, State> && ...)
std::expected< bool, WeightError > Emrys::upkeep::When< Predicate, Actions >::operator() ( State & state) const
inlinenodiscard

Tests state and runs the actions on it if the test holds.

Returns
whether any action changed the state, or a WeightError

The documentation for this struct was generated from the following file: