I am trying to construct some kind of "generic type alias", meaning I want to define a type as int
for example, but with a generic type argument which then makes it incompatible with instances of other types.
I tried doing this with alias templates:
template <typename T>
using NumberWithSemantics = int;
But the problem with this is that all instantiations, no matter the type T
, are considered equal, for example:
struct A {};
struct B {};
NumberWithSemantics<A> getThing() {
return 14;
}
int processDifferentThing(NumberWithSemantics<B> b) {
return b * 3;
}
int main() {
auto a = getThing();
return processDifferentThing(a); // unfortunately compiles just fine
}
Is there a way to define some kind of generic type alias that disallows mixing different template instantiations?