ft_containers/containers/iterators/pair.hpp
2022-11-26 17:05:21 +01:00

79 lines
2.2 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pair.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/22 13:39:29 by apommier #+# #+# */
/* Updated: 2022/11/26 13:39:18 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
namespace ft
{
template<class T1, class T2>
struct pair{
typedef T1 first_type;
typedef T2 second_type;
first_type first;
second_type second;
pair(): first(), second() {}
pair( const T1& x, const T2& y ) : first(x), second(y) {}
template<class U1, class U2>
pair(const pair<U1, U2>& p): first(p.first), second(p.second) { }
pair& operator= (const pair& pr) {
if (this != &pr)
{
this->first = pr.first;
this->second = pr.second;
}
return (*this);
}
~pair() {}
};
template <class T1, class T2>
bool operator== (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
{
return (lhs.first == rhs.first && lhs.second == rhs.second);
}
template <class T1, class T2>
bool operator!= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
{
return (!(lhs == rhs));
}
template <class T1, class T2>
bool operator< (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
{
return (lhs.first < rhs.first || (!(rhs.first < lhs.first) && lhs.second < rhs.second));
}
template <class T1, class T2>
bool operator<= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
{
return (!(rhs<lhs));
}
template <class T1, class T2>
bool operator> (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
{
return (rhs<lhs);
}
template <class T1, class T2>
bool operator>= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
{
return (!(lhs<rhs));
}
}