I had the following line in some C++ code inside of a template function:
auto swapper = std::swap<T>;
And when compiling, using T=int
, for instance, I get the following compiler error:
error: unable to deduce ‘auto’ from ‘swap<int>’
| auto swapper = std::swap<T>;
| ^~~~~~~
note: couldn’t deduce template parameter ‘auto’
If I explicitly declare the type for swapper
it works:
void (*swapper)(T&,T&) = std::swap<T>;
However, I am still puzzled as to why I can't declare swapper
as auto
?