20namespace gimo::detail::and_forward
22 template <
typename Nullable,
typename Action>
23 consteval void print_diagnostics()
25 if constexpr (!std::invocable<Action, value_result_t<Nullable>>)
27 static_assert(always_false_v<Nullable>,
"The and_forward algorithm requires an action invocable with the nullable's value.");
33 template <nullable Nullable,
typename Action>
34 static constexpr bool is_applicable_on =
requires {
35 requires std::invocable<Action, value_result_t<Nullable>>;
38 template <
typename Action, nullable Nullable>
39 static constexpr void on_value(Action&& action, Nullable&& opt)
41 GIMO_ASSERT(detail::has_value(opt),
"Nullable is empty while it's expected to contain a value.");
43 if constexpr (is_applicable_on<Nullable, Action>)
46 std::forward<Action>(action),
47 detail::forward_value<Nullable>(opt));
51 and_forward::print_diagnostics<Nullable, Action>();
55 template <
typename Action, nullable Nullable>
56 static constexpr void on_null(Action&& , [[maybe_unused]] Nullable&& opt)
58 GIMO_ASSERT(!detail::has_value(opt),
"Nullable contains a value while it's expected to be empty.");
60 if constexpr (!is_applicable_on<Nullable, Action>)
62 and_forward::print_diagnostics<Nullable, Action>();
constexpr auto and_forward(Action &&action)
Creates a terminating pipeline step that forwards the contained value to the specified action.
Definition AndForward.hpp:91