compare.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // ptr_compare.hpp
  3. // pointers
  4. //
  5. // Created by Sam Jaffe on 1/5/17.
  6. //
  7. #pragma once
  8. namespace pointers { namespace detail {
  9. template <typename Self> struct pointer_compare {
  10. friend bool operator==(Self const & lhs, Self const & rhs) {
  11. return lhs.get() == rhs.get();
  12. }
  13. friend bool operator<(Self const & lhs, Self const & rhs) {
  14. return lhs.get() < rhs.get();
  15. }
  16. friend bool operator!=(Self const & lhs, Self const & rhs) {
  17. return !(lhs == rhs);
  18. }
  19. friend bool operator>(Self const & lhs, Self const & rhs) {
  20. return rhs < lhs;
  21. }
  22. friend bool operator<=(Self const & lhs, Self const & rhs) {
  23. return !(rhs < lhs);
  24. }
  25. friend bool operator>=(Self const & lhs, Self const & rhs) {
  26. return !(lhs < rhs);
  27. }
  28. friend bool operator==(Self const & lhs, std::nullptr_t) { return !lhs; }
  29. friend bool operator<(Self const & lhs, std::nullptr_t) {
  30. return lhs.get() < nullptr;
  31. }
  32. friend bool operator!=(Self const & lhs, std::nullptr_t) { return !!lhs; }
  33. friend bool operator>(Self const & lhs, std::nullptr_t) {
  34. return nullptr < lhs;
  35. }
  36. friend bool operator<=(Self const & lhs, std::nullptr_t) {
  37. return !(nullptr < lhs);
  38. }
  39. friend bool operator>=(Self const & lhs, std::nullptr_t) {
  40. return !(lhs < nullptr);
  41. }
  42. friend bool operator==(std::nullptr_t, Self const & rhs) { return !rhs; }
  43. friend bool operator<(std::nullptr_t, Self const & rhs) {
  44. return nullptr < rhs.get();
  45. }
  46. friend bool operator!=(std::nullptr_t, Self const & rhs) { return !!rhs; }
  47. friend bool operator>(std::nullptr_t, Self const & rhs) {
  48. return rhs < nullptr;
  49. }
  50. friend bool operator<=(std::nullptr_t, Self const & rhs) {
  51. return !(rhs < nullptr);
  52. }
  53. friend bool operator>=(std::nullptr_t, Self const & rhs) {
  54. return !(nullptr < rhs);
  55. }
  56. };
  57. }}