Sometimes it works sometimes not:
template
void f(T t) {}
template
class MyClass {
public:
MyClass(T t) {}
};
void test
In C++17, it is possible to infer some types using auto, though the template parameters still need to be specified here:
#include
#include
template
auto print_stuff(T1 x, T2 y)
{
std::cout << x << std::endl;
std::cout << y << std::endl;
}
int main()
{
print_stuff(3,"Hello!");
print_stuff("Hello!",4);
return 0;
}
Using the -fconcepts flag in gcc, it is possible to infer the parameters, though this is not yet a part of the C++ standard:
#include
#include
auto print_stuff(auto x, auto y)
{
std::cout << x << std::endl;
std::cout << y << std::endl;
}
int main()
{
print_stuff(3,"Hello!");
print_stuff("Hello!",4);
return 0;
}