c++functionc++17stdfunction-signature

How to compare the signature of two functions?


Is there a way to check if two functions have the same signature? For example:

int funA (int a, int b);
int funB (int a, int b);
float funC (int a, int b);
int funD (float a, int b);

In this example, funA and funB is the only combination of functions that should return true.


Solution

  • Essentially you want to check if types of two functions are the same:

    std::is_same_v<decltype(funA), decltype(funB)>

    I wouldn't call this 'comparing signatures', as, if I remember correctly, return type is not a part of a signature (because it doesn't affect overload resolution).