comparable.hpp 813 B

123456789101112131415161718192021222324252627
  1. #pragma once
  2. namespace types {
  3. template <typename Self> struct EqualityComparable {
  4. friend bool operator==(Self const & lhs, Self const & rhs) {
  5. return lhs.get() == rhs.get();
  6. }
  7. friend bool operator!=(Self const & lhs, Self const & rhs) {
  8. return !(lhs == rhs);
  9. }
  10. };
  11. template <typename Self> struct Comparable : EqualityComparable<Self> {
  12. friend bool operator<(Self const & lhs, Self const & rhs) {
  13. return lhs.get() < rhs.get();
  14. }
  15. friend bool operator>(Self const & lhs, Self const & rhs) {
  16. return rhs.get() < lhs.get();
  17. }
  18. friend bool operator<=(Self const & lhs, Self const & rhs) {
  19. return !(rhs.get() < lhs.get());
  20. }
  21. friend bool operator>=(Self const & lhs, Self const & rhs) {
  22. return !(lhs.get() < rhs.get());
  23. }
  24. };
  25. }