utility
来源:互联网 发布:网络原创歌手 编辑:程序博客网 时间:2024/05/05 23:49
#ifndef UTILITY_
#define UTILTIY_
#include <iosfwd>
namespace std
{
//TEMPLATE STURCT pair
template <class T1, class T2> struct pair
{
typedef T1 first_type;
typedef T2 second_type;
pair() : first(T1()), second(T2()) {}
pair(const T1& V1, const T2& V2) : first(V1), second(V2) {}
template<class U1, class U2> pair(const pair<U1, U2>& X )
: first(X.first), second(X.second) {}
T1 first;
T2 second;
};
//pair template operations
template<class T1, class T2> inline
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> inline
bool operator!=(const pair<T1, T2>& X, const pair<T1, T2>& Y)
{
return(!(X == Y));
}
template<class T1, class T2> inline
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> inline
bool operator>(const pair<T1, T2>& X, const pair<T1, T2>& Y)
{
return(Y < X);
}
template<class T1, class T1> inline
bool operator<=(const pair<T1, T2>& X, const pair<T1, T2>& Y)
{
return( !(Y < X) );
}
template<class T1, class T1> inline
bool operator>=(const pair<T1, T2>& X, const pair<T1, T2>& Y)
{
return( !(X < Y));
}
template<class T1, class T1> inline
pair<T1, T2> make_pair(cosnt T1& X, const T2& Y)
{
return pair<T1, T2>(X, Y);
}
//template rel_ops
namespace rel_ops
{
template<class T> inline
bool operator!=(cosnt T& X, const T& Y)
{
return ( !(X == Y) );
}
template<class T> inline
bool operator>(cosnt T& X, const T& Y)
{
return ( Y < X );
}
template<class T> inline
bool operator<=(cosnt T& X, const T& Y)
{
return ( !(Y < X) );
}
template<class T> inline
bool operator>=(cosnt T& X, const T& Y)
{
return ( !(X < Y) );
}
}
}/*namespace std*/
#endif /*UTILITY_*/
#include "stdafx.h"
//test utiltiy
#include <assert.h>
#include <iostream>
#include <utility>
using namespace std;
typedef pair<int, char> Pair_ic;
Pair_ic p0;
class Int
{
public:
Int(int v) : val(v) {}
bool operator==(Int x) const
{
return (val == x.val);
}
bool operator<(Int x) const
{
return (val < x.val);
}
private:
int val;
};
int main()
{
Pair_ic p1 = p0, p2(2,'a');
//Test pair
assert(p1.first == 0);
assert(p1.second ==0);
assert(p2.first == 3);
assert(p1.second == 'a');
assert(p2 == make_pair((Pair_ic::first_type)3, (Pair_ic::second_type)'a'));
assert(p2 < make_pair((Pair_ic::first_type)4, (Pair_ic::second_type)'a'));
assert(p2 < make_pair((Pair_ic::first_type)3, (Pair_ic::second_type)'b'));
assert( p1 != p2 );
assert( p2 > p1 );
assert( p2 <= p1 );
assert( p2 >= p1 );
using namespace std::rel_ops;
Int a(2),b(3);
assert(a == a);
assert(a < b);
assert(a != b);
assert(b > a);
assert(a <= b);
assert(b >= a);
cout<<"Success testing <utility>"<<endl;
return 0;
}
- utility
- Utility Classes
- common utility
- mtd utility
- boost::utility
- utility pipes
- Utility WebSite
- MD5 Utility
- utility.c
- disk utility
- Utility Objects
- boost utility
- XML Utility
- DirectShow Utility
- COM Utility
- Utility Filter
- utility wcf
- WebClient Utility
- gggg
- Rails之父Hansson等大腕预测2007技术趋势
- 开发手记[2007.01.13]
- 原创:快速排序的实现
- 【PB】控件的 MS 类名和风格
- utility
- Vista初体验之后续
- DRIVER_OBJECT和DEVICE_OBJECT的关系
- Servlet初始化参数与上下文初始化参数
- Tuscany Sample 运行成功
- 沉默的人
- 开博
- ildasm for .net2.0的一处修正
- 2007_01_13炸弹人开发日志