-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfunctional_extended.h
53 lines (45 loc) · 1.22 KB
/
functional_extended.h
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
/*
* functional-extended header.
* written by Shuangquan Li, [email protected]
* created on 2016-8-6
* last edit on 2016-8-11, add maxone, minone
*/
#ifndef __FUNCTIONAL_EXTENDED_H__
#define __FUNCTIONAL_EXTENDED_H__
#include <functional>
template<typename T, typename Compare = std::less<T>>
struct maxone : std::binary_function<T, T, T> {
T operator() (const T& a, const T& b) {
return Compare()(a, b) ? b : a;
}
};
template<typename T, typename Compare = std::less<T>>
struct minone : std::binary_function<T, T, T> {
T operator() (const T& a, const T& b) {
return Compare()(a, b) ? a : b;
}
};
template<typename T, T mod>
struct plus_modulus : std::binary_function<T, T, T> {
T operator () (const T& a, const T& b) const {
T ret = (a + b) % mod;
if (ret < 0) ret += mod;
return ret;
}
};
template<typename T, T mod>
struct minus_modulus : std::binary_function<T, T, T> {
T operator () (const T& a, const T& b) {
T ret = (a - b) % mod;
if (ret < 0) ret += mod;
return ret;
}
};
template<typename T, T mod>
struct multiplies_modulus : std::binary_function<T, T, T> {
T operator () (const T& a, const T& b) {
return a * b % mod;
}
};
/* eof */
#endif