I can verify a function signature as follows:
template <typename>
struct FnType
{
static bool const valid = false;
};
struct FnType<void(int)>
{
static bool const valid = true;
};
void foo(int)
{
}
FnType<decltype(foo)>::valid; //true
How can I verify a class method signature?
class Y
{
public:
void foo(int)
{
}
};
FnType<decltype(&Y::foo)>::valid; //false??
I want to verify Y::foo
return type and argument types are valid.
You can add another partial specialization for member function pointers. e.g.
template <typename T>
struct FnType<void(T::*)(int)>
{
static bool const valid = true;
};
then
FnType<decltype(&Y::foo)>::valid; //true
LIVE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With