c++ - Type trait to match signatures of member functions of different classes -


what elegant way (possibly c++17-way) check if signatures of 2 methods defined in 2 different classes same?

for example:

template< typename ...ts > struct {     void f(ts...); };  template< typename ...ts > struct b {     void g(ts...); };  static_assert(has_same_signatures< decltype(&a<>::f), decltype(&b<>::g) >{}); static_assert(!has_same_signatures< decltype(&a< int >::f), decltype(&b< char >::g) >{}); //static_assert(has_same_signatures< decltype(&a< void >::f), decltype(&b<>::g) >{}); // don't know feasible w/o complexity 

it great, if types of non-member functions on either side allowed too.

maybe result type should entangled too.

the task origins common problem of matching signal/slot signatures in qt framework.

you like:

// static member functions / free functions same // if types same template <class t, class u> struct has_same_signature : std::is_same<t, u> { };  // member functions have same signature if they're 2 pointers members // same pointed-to type template <class t, class c1, class c2> struct has_same_signature<t c1::*, t c2::*> : std::true_type { }; 

note a<void> ill-formed can't have parameter of type void.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -