Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I verify a class method signature?

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.

like image 654
Frank Avatar asked Dec 06 '19 11:12

Frank


1 Answers

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

like image 121
songyuanyao Avatar answered Nov 17 '22 18:11

songyuanyao