STL(2)---<ulitiy>

Copyright (c) 1995 by P.J. Plauger.下面是ulitiy的一些简单的实现和使用/********************************************************************** * * Copyright (c)2015,WK Studios * * Filename: A.h * *
摘要由CSDN通过智能技术生成

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值