I wondered if there are specific rules that indicate whether this code should fail or not:
struct Foo { template<typename T> int bar() { static_assert(!std::is_same<T, float>::value, "Don't send floats please."); return 0; } int baz() { return 0; } }; int main() { using function_type = decltype(&Foo::bar<float>); function_type func = &Foo::baz; (void) func; }
This example does not work on GCC and Clang . Why should he fail? It seems that the choice of the type of function should not lead to the creation of an instance, let alone initiate a static statement. Why does this fail? And is there any other way to get the signature of the function template without creating an instance of the object?
My use case is to display the signature of a function template. Users of my code invoke my code with some parameters. Then I map these parameters to the argument of the function template to take its signatures, and then use the signature to retrieve the type of parameters that were not sent.
When the function forwards the link, there is no problem. However, if this function receives a parameter by value, I must send std::decay_t<Arg> as a template argument, so as not to cause compilation errors in the function body. But I canβt know if the function with which I receive the signature will receive the value of the link without additional reflection capabilities. If I could get the signature of the function template without creating it, that would be ideal.
source share