General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.7 KiB

  1. #pragma once
  2. #include "gp/algorithm/move.hpp"
  3. namespace gp{
  4. template<typename T1, typename T2>
  5. struct pair{
  6. T1 first;
  7. T2 second;
  8. pair() : first(), second() {}
  9. pair(const T1& a, const T2& b) : first(a), second(b) {}
  10. pair(pair&& v)
  11. : first(gp::move(v.first))
  12. , second(gp::move(v.second))
  13. {}
  14. template<typename U1, typename U2>
  15. pair(U1&& a, U2&& b)
  16. : first(gp::forward<U1>(a))
  17. , second(gp::forward<U2>(b))
  18. {}
  19. template<typename U1, typename U2>
  20. pair(pair<U1, U2>&& v)
  21. : first(gp::move(v.first))
  22. , second(gp::move(v.second))
  23. {}
  24. pair& operator=(pair&& v)
  25. {
  26. first = gp::move(v.first);
  27. second = gp::move(v.second);
  28. return *this;
  29. }
  30. };
  31. template<typename F, typename S>
  32. bool operator==(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  33. return lhs.first == rhs.first and lhs.second == rhs.second;
  34. }
  35. template<typename F, typename S>
  36. bool operator!=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  37. return lhs.first != rhs.first or lhs.second != rhs.second;
  38. }
  39. template<typename F, typename S>
  40. bool operator<=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  41. if(lhs.first > rhs.first) {
  42. return false;
  43. } else if(lhs.first == rhs.first) {
  44. return lhs.second <= rhs.second;
  45. }
  46. return true;
  47. }
  48. template<typename F, typename S>
  49. bool operator>=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  50. if(lhs.first < rhs.first) {
  51. return false;
  52. } else if(lhs.first == rhs.first) {
  53. return lhs.second >= rhs.second;
  54. }
  55. return true;
  56. }
  57. template<typename F, typename S>
  58. bool operator<(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  59. return !(lhs >= rhs);
  60. }
  61. template<typename F, typename S>
  62. bool operator>(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  63. return !(lhs <= rhs);
  64. }
  65. }