So that you can try, put A
in the namespace, create operator ==
as a non-member of the template in this namespace, and let ADL take care of this.
Edit:. For your edited example, where you want the equality check to compare each part of the class with the other relevant part, the DyP clause might work. For instance:
Now compare this again in the code used:
// ... bi = 1, bb.i = 1; bj = 1, bb.j = 42; cout << boolalpha << (b == bb) << '\n'; bj = 42; cout << (b == bb) << '\n'; ai = 2, aa.i = 3; cout << (aa == a) << '\n';
outputs:
bool stuff::operator==(const T&, const T&) [with T = stuff::B] false bool stuff::operator==(const T&, const T&) [with T = stuff::B] true bool stuff::operator==(const T&, const T&) [with T = stuff::A] false
source share