Skip to content

Commit

Permalink
sfinae-protect operator== StringRef overload
Browse files Browse the repository at this point in the history
Unrestricted operator==(T, StringRef) participates in overload
resolution even if StringRef::operator== cannot be called with T.
  • Loading branch information
Vojtech Havel committed Mar 17, 2022
1 parent cc9e4c5 commit 3f02bcc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/stringref.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@ struct StringRef {
};

template <class T> inline
bool operator==(T a, const StringRef &b) { return b == a; }
auto operator==(T a, const StringRef &b) -> decltype(b.operator==(a)) { return b == a; }
template <class T> inline
bool operator!=(T a, const StringRef &b) { return b != a; }
auto operator!=(T a, const StringRef &b) -> decltype (b.operator!=(a)) { return b != a; }
template <class T> inline
bool operator>=(T a, const StringRef &b) { return b <= a; }
auto operator>=(T a, const StringRef &b) -> decltype (b.operator<=(a)) { return b <= a; }
template <class T> inline
bool operator>(T a, const StringRef &b) { return b < a; }
auto operator>(T a, const StringRef &b) -> decltype(b.operator<(a)) { return b < a; }
template <class T> inline
bool operator<=(T a, const StringRef &b) { return b >= a; }
auto operator<=(T a, const StringRef &b) -> decltype(b.operator>=(a)) { return b >= a; }
template <class T> inline
bool operator<(T a, const StringRef &b) { return b > a; }
auto operator<(T a, const StringRef &b) -> decltype(b.operator>(a)) { return b > a; }

inline std::ostream &operator<<(std::ostream &os, const StringRef &a) {
return a.len ? os.write(a.p, a.len) : os; }
Expand Down

0 comments on commit 3f02bcc

Please sign in to comment.