comparable.hpp 819 B

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