I am trying to write a caller function that can take an optional argument of varying template type.
#include <iostream>
#include <string>
void f_int(int x){std::cout << "f_int\n";}
void f_double(double x){std::cout << "f_double\n";}
void f_void(void){std::cout << "f_void\n";}
template<typename T>
void caller(void (*fun)(T), T arg)
{
(*fun)(arg);
}
int main()
{
caller(f_int, 3);
caller(f_double, 2.1);
caller(f_void); // compilation error
caller(f_void, void); // compilation error
void* p;
caller(f_void, *p); // compilation error
}
When writing this code, I was hoping that T could be of type void. Can it be? If yes, why does the above code not work? Is void a valid type or is only void* a valid type?