This is a response to a response to another SO message .
I have the following working code with the expected output.
#include <iostream>
template <typename T>
T twice(T in)
{
return 2*in;
}
struct Foo
{
Foo operator+(int (*func)(int in)) const
{
Foo ret{data};
ret.data += func(ret.data);
return ret;
}
int data;
};
int main()
{
Foo f1{20};
Foo f2 = f1 + twice;
Foo f3 = f1 + twice<int>;
std::cout << f2.data << std::endl;
std::cout << f3.data << std::endl;
}
I did not know until yesterday that the compiler can output parameters such as a function template even without an argument. In the above code of expression
f1 + twice
and
f1 + twice<int>
lead to identical values.
My question is: where in the C ++ 03 / C ++ 11 standard can we find the necessary supporting documentation for the detection logic of an automatic compiler type?
source
share