In a comparison operator:
template<class R1, class R2>
bool operator==(Manager<R1> m1, Manager<R2> m2) {
return m1.internal_field == m2.internal_field;
}
Is there any way I could enforce that R1 and R2 must have a supertype or subtype relation? That is, I’d like to allow either R1 to be derived from R2, or R2 to be derived from R1, but disallow the comparison if R1 and R2 are unrelated types.
A trait you want might look like this:
Then you just need a static assert of some sort:
Then put the two together:
If one does not derive from the other, the function will not compile. (Your error will be similar to “
static_assert<false>not defined”, and it will point to that line.)