Template Function poet::dispatch(Functor&&, FirstParam&&, Rest&&…)

Function Documentation

template<typename Functor, typename FirstParam, typename ...Rest, std::enable_if_t<detail::is_dispatch_param_v<FirstParam>, int> = 0>
auto poet::dispatch(Functor &&functor, FirstParam &&first_param, Rest&&... rest) -> decltype(auto)

Dispatches runtime integers to compile-time specializations.

Accepts leading dispatch_param arguments, followed by any remaining arguments, which are forwarded to functor untouched. functor is invoked in whichever form it provides, with the value form preferred when both are viable (which is what makes a generic lambda work):

  • functor(std::integral_constant<V, Value>{}..., args...): values

  • functor.template operator()<Value...>(args...): template parameters

Warning

On a miss this overload is silent: it returns a default-constructed result (or nothing, for void) and never calls functor. Prefix the call with poet::throw_on_no_match to get a no_match_error instead.

Parameters:
  • functor – The callable to specialize. Bound by reference, so a stateful functor’s mutations stay visible to the caller.

  • first_param – First dispatch_param.

  • rest – Further dispatch_params (consecutive ones form a cartesian product), then the arguments to forward.