-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctional.h
More file actions
56 lines (50 loc) · 1.41 KB
/
Functional.h
File metadata and controls
56 lines (50 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* @Author : mark
* @Date : 2020-05-26
* @copyleft Apache 2.0
*/
// 作为一元函数对象的基类,只定义了参数和返回值的类型
template<class T>
struct unary_function{
typedef T argument_type;
typedef T result_type;
};
//binary_function:作为二元函数基类,只定义了参数和返回值的类型
template<class T>
struct binary_function{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
};
//用于返回较小值
template<class T>
struct less{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
result_type operator()(const first_argument_type& x, const second_argument_type& y){
return x < y;
}
}
//判断是否相等
template<class T>
struct equal_to{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
result_type operator()(const first_argument_type& x, const second_argument_type& y){
return x == y;
}
}
//判断同一性
template <class T>
struct identity: public unary_function<T>{
//函数调用操作符
const T& operator()(const T& x) const {return x;}
}
//判断键值,map会用到
template <class T>
struct select1st: public unary_function<T, typename T::first_type>{
//函数调用操作符
const typename T::first_type& operator()(const T& x) const {return x.first;}
}