This does not work, you will need to specify the parameter at compile time. The following would be done:
template<int Value>
double GetVar() {return 0.0;};
template<>
int GetVar<42>() {return 42;}
auto x = GetVar<0>();
auto y = GetVar<42>();
Another option is to pass std :: integral_constant, for example:
template<int Value>
using v = std::integral_constant<int, Value>;
template<typename T>
double GetVar(T) {return 0;};
int GetVar(v<42>) {return 42;};
auto x = GetVar(v<0>());
auto y = GetVar(v<42>());
source
share