vari
Loading...
Searching...
No Matches
dispatch.h
1
23#pragma once
24
25#include "vari/bits/dispatch.h"
26
27namespace vari
28{
29
30// Given `i` calls `Cnv` callable with `i` as _template argument_ and passes the result into best
31// match of callable out of `fn` set.
32//
33// `i` has to fit in range 0..N-1, any other value is undefined behavior.
34template < std::size_t N, typename Cnv, typename... Fn >
35constexpr decltype( auto ) dispatch( index_type i, Cnv&& cnv, Fn&&... fn )
36{
37 using types = factory_result_types_t< N, Cnv >;
38
39 typename _check_unique_invocability< types >::template with_pure_value< Fn... > _{};
40
41 return _dispatch_index< 0, N >( i, [&]< index_type j >() -> decltype( auto ) {
42 auto&& item = cnv.template operator()< j >();
43
44 return _dispatch_fun( (decltype( item )&&) item, (Fn&&) fn... );
45 } );
46}
47
48} // namespace vari
MIT License.
Definition: dispatch.h:32