87 lines
1.4 KiB
C++
87 lines
1.4 KiB
C++
#ifndef PAIR_HPP
|
|
# define PAIR_HPP
|
|
|
|
# define PR_TPL template < class T1, class T2 >
|
|
# define PR pair<T1, T2>
|
|
|
|
namespace ft {
|
|
|
|
PR_TPL
|
|
struct pair {
|
|
|
|
typedef T1 first_type;
|
|
typedef T2 second_type;
|
|
|
|
pair();
|
|
template< typename U, typename V >
|
|
pair(const pair<U,V>& pr);
|
|
pair(const first_type& a, const second_type& b);
|
|
|
|
T1 first;
|
|
T2 second;
|
|
};
|
|
|
|
|
|
/************
|
|
* copliens :
|
|
************/
|
|
PR_TPL PR::
|
|
pair() {}
|
|
PR_TPL template< typename U, typename V > PR::
|
|
pair(const pair<U,V>& pr)
|
|
: first(pr.first)
|
|
, second(pr.second) {
|
|
}
|
|
PR_TPL PR::
|
|
pair(const first_type& a, const second_type& b)
|
|
: first(a)
|
|
, second(b) {
|
|
}
|
|
|
|
|
|
|
|
/************************
|
|
* non-member functions :
|
|
************************/
|
|
PR_TPL
|
|
bool operator==(const PR& lhs, const PR& rhs) {
|
|
|
|
return (lhs.first == rhs.first) && (lhs.second == rhs.second);
|
|
}
|
|
PR_TPL
|
|
bool operator<(const PR& lhs, const PR& rhs) {
|
|
|
|
return (lhs.first < rhs.first
|
|
|| ( !(rhs.first < lhs.first) && (lhs.second < rhs.second) )
|
|
);
|
|
}
|
|
PR_TPL
|
|
bool operator!=(const PR& lhs, const PR& rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
}
|
|
PR_TPL
|
|
bool operator>(const PR& lhs, const PR& rhs) {
|
|
|
|
return (rhs < lhs);
|
|
}
|
|
PR_TPL
|
|
bool operator<=(const PR& lhs, const PR& rhs) {
|
|
|
|
return !(lhs > rhs);
|
|
}
|
|
|
|
PR_TPL
|
|
bool operator>=(const PR& lhs, const PR& rhs) {
|
|
|
|
return !(lhs < rhs);
|
|
}
|
|
|
|
} // namespace ft
|
|
|
|
# undef PR
|
|
# undef PR_TPL
|
|
|
|
#endif
|
|
|