A solution that mostly depends on your actual function is to define it as it follows:
template<typename T> constexpr void func(T val) { }
Then invoke it as f(5) and have the template parameter deduced from the parameter of the function itself.
Otherwise, in C++14, you cannot avoid using the pattern template<typename T, T value>.
It is the same pattern used by the Standard Template Library, see as an example the definition of std::integral_constant.
A possible solution that mitigates (maybe) the boilerplate is based on the use of a struct, as an example:
template<typename T> struct S { template<T value> static void func() {} };
You can the do something like this:
using IntS = S<int>; // .... IntS::func<5>();
With the upcoming revision C++17, you will manage to do it as it follows:
template<auto value> void func() {}
This can be invoked as f<5>(), that is what you are looking for..
autotype.template<typename T> constexpr void func(T val) { }and call it asf(5)?templatetypes can only be simple types, likeintandbool. You can't put adouble, for example, instead of thatint, right? So I'm wondering whether it's ever useful to do this.template<typename T, T val> func(std::integral_constant<T, val>) { cout << val; }