Hi
ru**********@gmail.com wrote:
Is there any way to force user to specify template parameters
explicitly? I want to do the following:
f<int>(1); // Normal
f(1); // This should give an error
Any ideas?...
You would have to make T undeducible. (word sounds wrong?)
You could for example use an indirection:
template<typename T>
struct f_helper
{
const T& value;
f_helper(const T& value) : value(value) {}
operator const T& () const { return value; }
};
template<typename T>
void f(const f_helper<T>& h)
{
const T& value = h;
// ...
}
Then f(1) fails to compile, while f<int>(1) will still compile.
Markus