comparable.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #if __cplusplus >= 202002L
  11. friend std::partial_ordering operator<=>(Self const & lhs,
  12. Self const & rhs) {
  13. return lhs == rhs ? std::partial_ordering::equivalent
  14. : std::partial_ordering::unordered;
  15. }
  16. #endif
  17. };
  18. template <typename Self> struct Comparable {
  19. friend bool operator==(Self const & lhs, Self const & rhs) {
  20. return lhs.get() == rhs.get();
  21. }
  22. friend bool operator!=(Self const & lhs, Self const & rhs) {
  23. return !(lhs == rhs);
  24. }
  25. friend bool operator<(Self const & lhs, Self const & rhs) {
  26. return lhs.get() < rhs.get();
  27. }
  28. friend bool operator>(Self const & lhs, Self const & rhs) {
  29. return rhs.get() < lhs.get();
  30. }
  31. friend bool operator<=(Self const & lhs, Self const & rhs) {
  32. return !(rhs.get() < lhs.get());
  33. }
  34. friend bool operator>=(Self const & lhs, Self const & rhs) {
  35. return !(lhs.get() < rhs.get());
  36. }
  37. #if __cplusplus >= 202002L
  38. friend auto operator<=>(Self const & lhs, Self const & rhs) {
  39. return lhs.get() <=> rhs.get();
  40. }
  41. #endif
  42. };
  43. }