It can be done. But believe me when I say that you are asking the wrong question. So, what follows to your question, even the thought that this is a bad idea, almost always.
What you can actually do is create 50 different programs, one for each of the 50 possible sizes, and then conditionally switch to the one you want.
template<int n> struct prog { void run() {
Call switcher<50>::run( value ); , and if the value is 0-50, prog<value>::run() called. Within prog::run the template parameter is a compile-time value.
Awful hack, and most likely you are better off using a different solution, but this is what you asked for.
The following is a tabular version of C ++ 14:
template<size_t N> using index_t = std::integral_constant<size_t, N>; // C++14 template<size_t M> struct magic_switch_t { template<class...Args> using R=std::result_of_t<F(index_t<0>, Args...)>; template<class F, class...Args> R<Args...> operator()(F&& f, size_t i, Args&&...args)const{ if (i >= M) throw i; // make a better way to return an error return invoke(std::make_index_sequence<M>{}, std::forward<F>(f), i, std::forward<Args>(args)...); } private: template<size_t...Is, class F, class...Args> R<Args...> invoke(std::index_sequence<Is...>, F&&f, size_t i, Args&&...args)const { using pF=decltype(std::addressof(f)); using call_func = R<Args...>(*)(pF pf, Args&&...args); static const call_func table[M]={ [](pF pf, Args&&...args)->R<Args...>{ return std::forward<F>(*pf)(index_t<Is>{}, std::forward<Args>(args)...); }... }; return table[i](std::addressof(f), std::forward<Args>(args)...); } };
magic_switch_t<N>{}( f, 3, blah1, blah2, etc ) will call f(index_t<3>{}, blah1, blah2, etc) .
Some C ++ 14 compilers will strangle a variational package extension containing lambda. It doesn't matter, you can make a workaround, but the workaround is ugly.
The features of C ++ 14 are all optional: you can implement all of this in C ++ 11, but again, ugly.
The passed f should basically be the object of the function (either a lambda that takes auto as the first argument, or manual). Passing a function name directly will not work, because it works best when the first argument becomes a compile-time value.
You can wrap a function template with a lambda or function object.