Template Function Acts::template_switch¶
Defined in File Helpers.hpp
Function Documentation¶
-
template<template<size_t> class
Callable
, size_tN
, size_tNMAX
, typename ...Args
>
decltype(Callable<N>::invoke(std::declval<Args>()...))Acts
::
template_switch
(size_t v, Args&&... args)¶ Dispatch a call based on a runtime value on a function taking the value at compile time.
This function allows to write a templated functor, which accepts a
size_t
like paramater at compile time. It is then possible to make a call to the corresponding instance of the functor based on a runtime value. To achieve this, the function essentially created a if cascade betweenN
andNMAX
, attempting to find the right instance. Because the cascade is visible to the compiler entirely, it should be able to optimize.- Note
Callable
is expected to have a static member functioninvoke
that is callable withArgs
- Template Parameters
Callable
: Type which takes a size_t as a compile time paramN
: Value from which to start the dispatch chain, i.e. 0 in most casesNMAX
: Maximum value up to which to attempt a dispatch
- Parameters
v
: The runtime value to dispatch onargs
: Additional arguments passed toCallable::invoke()
.