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.

84 lines
1.8 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. constexpr pair()
  9. : first()
  10. , second()
  11. {}
  12. constexpr pair(const T1& a, const T2& b)
  13. : first(a)
  14. , second(b)
  15. {}
  16. constexpr pair(pair&& v)
  17. : first(gp::move(v.first))
  18. , second(gp::move(v.second))
  19. {}
  20. template<typename U1, typename U2>
  21. constexpr pair(U1&& a, U2&& b)
  22. : first(gp::forward<U1>(a))
  23. , second(gp::forward<U2>(b))
  24. {}
  25. template<typename U1, typename U2>
  26. constexpr pair(pair<U1, U2>&& v)
  27. : first(gp::move(v.first))
  28. , second(gp::move(v.second))
  29. {}
  30. constexpr pair& operator=(pair&& v)
  31. {
  32. first = gp::move(v.first);
  33. second = gp::move(v.second);
  34. return *this;
  35. }
  36. };
  37. template<typename F, typename S>
  38. constexpr bool operator==(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  39. return lhs.first == rhs.first and lhs.second == rhs.second;
  40. }
  41. template<typename F, typename S>
  42. constexpr bool operator!=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  43. return lhs.first != rhs.first or lhs.second != rhs.second;
  44. }
  45. template<typename F, typename S>
  46. constexpr bool operator<=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  47. if(lhs.first > rhs.first) {
  48. return false;
  49. } else if(lhs.first == rhs.first) {
  50. return lhs.second <= rhs.second;
  51. }
  52. return true;
  53. }
  54. template<typename F, typename S>
  55. constexpr bool operator>=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  56. if(lhs.first < rhs.first) {
  57. return false;
  58. } else if(lhs.first == rhs.first) {
  59. return lhs.second >= rhs.second;
  60. }
  61. return true;
  62. }
  63. template<typename F, typename S>
  64. constexpr bool operator<(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  65. return !(lhs >= rhs);
  66. }
  67. template<typename F, typename S>
  68. constexpr bool operator>(const pair<F, S>& lhs, const pair<F, S>& rhs) {
  69. return !(lhs <= rhs);
  70. }
  71. }