📄 aa.cpp
字号:
#include<assert.h>
#include<iostream>
#include<utility>
using namespace std;
typedef pair<int,char> Pair_ic;//使用utility中的操作,定义了一个Pair_ic类型
Pair_ic p0;
class Int //用于测试rel_pos中的操作
{
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;
};
typedef pair<pair<int,char>,int> Trio;
Trio t0;
//TEST <utility>
int main()
{
Pair_ic p1=p0,p2(3,'a');//在这里,如果使用p2=(3,'a')不能通过,因为这里的‘a’不被承认为const型,而如果像例子中的则可以
Trio t1=t0,t2(p1,4);//三个的这样做。
/*测试三个的*/
t1.first.first=2;
t1.first.second='b';
t1.second=4;
/*测试三个的*/
//TEST pair ,在pair中是将数值组装成一个结构体,并对其进行一些比较操作
assert(p1.first == 0);
assert(p1.second == 0);
assert(p2.first == 3);
assert(p2.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)'b'));
assert(p2 < make_pair((Pair_ic::first_type)3,(Pair_ic::second_type)'b'));
assert(p1 != p2);
assert(p2 > p1);
assert(p2 <= p2);
assert(p2 >= p2);
//Test rel_pos //在rel_pos中封装了对两个类的比较操作
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -