Skip to content

Instantly share code, notes, and snippets.

@fastasturtle
Last active March 9, 2017 13:41
Show Gist options
  • Save fastasturtle/925834f19e9e95c5b66d90cddfc05758 to your computer and use it in GitHub Desktop.
Save fastasturtle/925834f19e9e95c5b66d90cddfc05758 to your computer and use it in GitHub Desktop.
namespace ops {
struct gatekeeper {};
template<typename T>
bool operator>(T const &a, T const &b) {
return b < a;
}
template<typename T>
bool operator==(T const &a, T const &b) {
return !(a < b) && !(b < a);
}
// ...
}
struct my_struct : private ops::gatekeeper {
int a;
my_struct(int a) : a{a} {}
bool operator<(my_struct const& other) const {
return a < other.a;
}
bool operator==(my_struct const& other) const {
return a == other.a;
}
};
void test(my_struct s1, my_struct s2) {
s1 < s2;
s1 > s2;
s1 == s2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment