Others have mentioned the solution using std::is_same
and decltype
.
Now to generalize the comparison for an arbitrary number of function signatures, you can do the following
#include <type_traits> // std::is_same, std::conjunction_v
template<typename Func, typename... Funcs>
constexpr bool areSameFunctions = std::conjunction_v<std::is_same<Func, Funcs>...>;
and compare as many functions as one like
areSameFunctions<decltype(funA), decltype(funB), decltype(funC)>
(See Live Demo)
Or for less typing (i.e. without decltype
), make it as a function
template<typename Func, typename... Funcs>
constexpr bool areSameFunctions(Func&&, Funcs&&...)
{
return std::conjunction_v<std::is_same<Func, Funcs>...>;
}
and call simply by
areSameFunctions(funA, funB, funC)
(See Live Demo)