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);
}
}
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++ 中 make_pair 的简易实现
- c++ 模板学习笔记:类模板和函数模板实现pair(权哥)
- c++版Pair实现
- 在C++中实现属性
- C++实现单件的初探
- C++设计模式:Singleton的模板实现之一
- Singleton模式的C++实现研究(转贴)
- 分析模式-计量的C++实现——完美版本
- 在Delphi与C++之间实现函数与对象共享
- 使用c++实现Format函数
- 用PHP实现通过Web执行C/C++程序
- 在Delphi与C++之间实现函数与对象共享
- 用 C++ 实现 C# 中的 委托/事件 (2-delegate event functor)
- 用C++实现C#中的委托/事件(标准C++之升级版)
- 用C++ std::priority_queue 实现哈夫曼算法
- C++机理:虚拟机制的实现[兼谈对比于传统机制]
- C++面向对象特性实现机制的初步分析 Part2
- 分析模式-计量的C++实现——回复ch0877
- 小写转大写金额在C++中的实现
- 用 C++ 实现 C# 中的 委托/事件 (5-functor2)