Sometimes it can be useful to call guards from another guard. For example, these two guards:
constexpr auto is_small =
maki::guard_e([](
const some_event& evt)
{
return evt.size < 10;
});
constexpr auto is_large =
maki::guard_e([](
const some_event& evt)
{
return evt.size > 1000;
});
... can be composed like so:
constexpr auto is_average =
maki::guard_e([](
const some_event& evt)
{
return !is_small.callable(evt) && !is_large.callable(evt);
});
But this is a bit verbose and inconvenient.
Fortunately, Maki allows you to compose guards using boolean operators (!
, &&
, ||
and !=
). For example:
constexpr auto is_average_2 = !is_small && !is_large;
You can also inline such expressions in transition tables:
(maki::init, some_state)
(some_state, some_other_state, maki::event<some_event>, some_action, !is_small && !is_large)
;