STL(2)---
2745 ワード
Copyright (c) 1995 by P.J. Plauger.
次はulitiyの簡単な実装と使用です.
次は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!
";
}
else
{
cout<<"Success
";
}
}
int main()
{
Pair<int,char> pr(3,'a');
Pair<int,char> p1;
Require(pr.second=='a');
Require(p1 != pr);
return 0;
}