您的位置:首页 > 编程语言 > C语言/C++

c++中pair的实现

2014-07-08 11:22 197 查看
namespace std{
template<class T1 , class T2>
struct pair
{
typedef T1 first_type;
typedef T2 second_type;

T1 first;
T2 second;

pair() :first(T1()), second(T2()){}

template<class U, class V>
pair(const pair<U, V>& p) : first(p.first), second(p.second){

}

};

template<class T1 , class T2>
bool operator == (const pair<T1, T2>&, const pair<T1, T2>&);
template<class T1, class T2>
bool operator< (const pair<T1, T2>&, const pair<T1, T2>&);
template<class T1,class T2>
pair<T1, T2> make_pair(const T1&, const T2&);

template<class T1,class T2>
bool  operator==(const pair<T1, T2>& x, const pair<T1, T2>& y){
return x.first == y.first && x.second == y.second;
}

template <class T1 , class T2>
bool operator<(const pair<T1, T2> & x, const pair<T1, T2>& y){
return x.first < y.first || (!(y.first < x.first) && x.second < y.second);
}

template<class T1 , class T2>
pair<T1, T2> make_pair(const T1& X, const T2& y){
return pair<T1, T2>(x, y);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++