STL(2)---<ulitiy>

来源:互联网 发布:php在线解密工具 编辑:程序博客网 时间:2024/05/20 07:37

Copyright (c) 1995 by P.J. Plauger.

下面是ulitiy的一些简单的实现和使用

/**********************************************************************     * *   Copyright (c)2015,WK Studios   * *   Filename:  A.h * *   Compiler: GCC  vc 6.0    * *   Author:WK     * *   Time: 2015 7 8  * **********************************************************************/#include <iostream>using namespace std;template <class T1,class T2>struct  Pair{      typedef T1 first_type;  typedef T2 second_typel;  Pair():first(T1()),second(T2()){}  Pair(const T1 &v1,const T2 &v2)  :first(v1),second(v2)  {}  T1 first;  T2 second;};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 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<y);}template<class T1,class T2>inline Pair<T1,T2> make_Pair(const Pair<T1,T2>&x,const Pair<T1,T2>&y){return Pair<T1,T2>(x,y);}class Int{public:Int(int v=0):val(v){}bool operator==(Int &x){return (val == x.val);}bool operator<(Int &y){return (val <y.val);}private:int val;};namespace rei_pos{template<class T> inline bool operator != (const T&x,const T&y){return !(x==y);}template<class T>inline bool operator >(const T&x,const T&y){return (x>y);}template<class T>inline bool operator<=(const T&x,const T&y){return (!(x>y));}template<class T>inline bool operator>=(const T&x,const T&y){return (!(x<y));}}void Require(bool a){if(!a){cout<<"ERRO!\n";}else{cout<<"Success\n";}}int main(){  Pair<int,char> pr(3,'a');  Pair<int,char> p1;  Require(pr.second=='a');  Require(p1 != pr);return 0;}


0 0
原创粉丝点击