Consider the following two snippets:
// Option (1).
boost::mp11::mp_with_index<N>(i,
[&](const auto i){ function<i>(/* args... */); });
and
// Option (2).
inline static const std::array<std::function<void(/* Args... */)>, N>
functionArray{function<0>, ..., function<N-1>};
functionArray[i](/* args... */);
where N is a compile time size approximately in the range [0, 20], i is a runtime index between 0 and N-1, and template <size_t I> function(/* Args... */) is a template function with a known signature. Which of the two options is the fastest one?
Note: I know that boost::mp11::mp_with_index basically creates a switch statement that allows to convert a runtime index to a compile time one. This introduces some indirection, but I expect this to not be too costly. Similarly, I know that std::function introduces some indirection due to type erasure. My question is: which of the two indirection kinds is the most efficient?