|
|
- #pragma once
-
- #include "gp/algorithm/move.hpp"
-
- namespace gp{
- template<typename T1, typename T2>
- struct pair{
- T1 first;
- T2 second;
-
- pair() : first(), second() {}
-
- pair(T1& a, T2& b) : first(a), second(b) {}
- pair(T1& a, T2&& b) : first(a), second(gp::move(b)) {}
- pair(T1&& a, T2& b) : first(gp::move(a)), second(b) {}
- pair(T1&& a, T2&& b) : first(gp::move(a)), second(gp::move(b)) {}
-
- pair(const pair& v)
- : first(v.first)
- , second(v.second)
- {}
-
- pair(pair& v)
- : first(v.first)
- , second(v.second)
- {}
-
- pair(pair&& v)
- : first(gp::move(v.first))
- , second(gp::move(v.second))
- {}
-
- template<typename U1, typename U2>
- pair(pair<U1, U2>&& v)
- : first(gp::move(v.first))
- , second(gp::move(v.second))
- {}
-
- pair& operator=(pair&& v)
- {
- first = gp::move(v.first);
- second = gp::move(v.second);
- return *this;
- }
- };
-
- template<typename T1, typename T2>
- pair<T1, T2> make_pair(T1 f, T2 s) {
- return pair<T1, T2>(f, s);
- }
-
- template<typename F, typename S>
- bool operator==(const pair<F, S>& lhs, const pair<F, S>& rhs) {
- return lhs.first == rhs.first and lhs.second == rhs.second;
- }
-
- template<typename F, typename S>
- bool operator!=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
- return lhs.first != rhs.first or lhs.second != rhs.second;
- }
-
- template<typename F, typename S>
- bool operator<=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
- if(lhs.first > rhs.first) {
- return false;
- } else if(lhs.first == rhs.first) {
- return lhs.second <= rhs.second;
- }
- return true;
- }
-
- template<typename F, typename S>
- bool operator>=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
- if(lhs.first < rhs.first) {
- return false;
- } else if(lhs.first == rhs.first) {
- return lhs.second >= rhs.second;
- }
- return true;
- }
-
- template<typename F, typename S>
- bool operator<(const pair<F, S>& lhs, const pair<F, S>& rhs) {
- return !(lhs >= rhs);
- }
-
- template<typename F, typename S>
- bool operator>(const pair<F, S>& lhs, const pair<F, S>& rhs) {
- return !(lhs <= rhs);
- }
- }
|