I would like to check if two types are the same, but regardless of their template parameters. Something like this:
template<class T>
class A {};
class B {};
int main() {
cout << std::is_same_template<A<int>, A<string>>::value << endl; // true
cout << std::is_same_template<A<int>, B>::value << endl; // false
}
I am aware of std::is_same
for checking if two types match exacty.
A reason why I need this:
I have a templated method that can be called with any type, but I would like to prohibit that is is called with type A
(which is templated), possibly by using a static_assert
. Were A
not templated, I believe it could be done easily using std::is_same
, but now, I have a problem...
EDIT: I can manually exclude A for a few common Ts, using, I am looking for a way to do it for all T:
static_assert(!std::is_same<parameter_type, A<int>>::value, "Cannot use this function with type A<T>");
static_assert(!std::is_same<parameter_type, A<double>>::value, "Cannot use this function with type A<T>");
static_assert(!std::is_same<parameter_type, A<bool>>::value, "Cannot use this function with type A<T>");