Someone else will formulate this better, but I think the problem is that the compiler cannot output T to Wrap<T> without passing the Wrap object to it. I think your situation should be resolved if you explicitly give the operator== argument of the template: operator==<int>(7, 4) , for example, should work.
I don't have a compiler in front of me, but here's my attempt:
template<typename T> typename std::enable_if<std::is_convertible<Wrap<T>, T>::value, bool>::type operator==(const Wrap<T>& l, const T& r) { return l.stuff == Wrap<T>(r).stuff; } template<typename T> typename std::enable_if<std::is_convertible<Wrap<T>, T>::value, bool>::type operator==(const T& l, const Wrap<T>& r) { return r == l;
This should work if both sides are Wrap and the other side is not. You can also do both sides as const T& , however if Wrap really implicitly built from any T , you can use your operator== for many unintended comparisons, even int s, string s, etc.
David
source share