graph LR
A(STL提供的仿函数) --> B(算术类仿函数)
A --> C(关系运算符仿函数)
A --> D(逻辑运算仿函数)
A --> E("位运算函数(since C++11)")
B --> B1(plus<T>) --> 相加
B --> B2(minus<T>) --> 相减
B --> B3(multiplies<T>) --> 相乘
B --> B4(divides<T>) --> 相除
B --> B5(modulus<T>) --> 取模
B --> B6(negate<T>) --> 取否
C --> C1(equal_to<T>) --> 等于
C --> C2(not_equal_to<T>) --> 不等于
C --> C3(greater<T>) --> 大于
C --> C4(greater_equal<T>) --> 大于等于
C --> C5(less<T>) --> 小于
C --> C6(less_equal<T>) --> 小于等于
D --> D1(logical_and<T>) --> 逻辑与
D --> D2(logical_or<T>) --> 逻辑或
D --> D3(logical_no<T>) --> 逻辑非
E --> E1(bit_and<T>) --> 按位与
E --> E2(bit_or<T>) --> 按位或
E --> E3(bit_xor<T>) --> 按位异或
#include<iostream> usingnamespace std; classCompare { public: booloperator()(int a, int b) { return a < b; } }; template <classFunction> voidcomp(int a, int b, Function func) { if (func(a, b)) { cout << b << " is bigger than " << a << endl; } else { cout << a << " is bigger than " << b << endl; } } intmain() { int a = 6; int b = 2; Compare com; comp(a, b, com); }