Is it somehow possible to reflect the type of the argument of a function at compile time?
So that
int b = add(3, 6)
Would result in a template instantiation in the form of
int add(int a, int b) { return a + b }
out of some however declared function template
A add(A a, B b) { return a + b }
I don’t know if that is possible with templates they do not really seem to be made for heavy meta-programming.
Templates do all their magic at compile time, but that seems to be quite adequate for what you’re asking:
It does get a bit more complex when the two might not match, so (for example) you could add an
intto adoubleand get adoubleresult. The current standard doesn’t really support that1; with C++0x you can look intoautoanddecltypefor such tasks.1Though Boost
typeofwill often do the job.