STLToys 是练习时实现的一个C++ STL标准库的玩具.
仿函数 functors 在 C++标准规格定案后 又叫做 函数对象 function objects.
仿函数要想可配接 必须定义自己的类型 让配接器取出. 为了方便 在 stl_function.h
中定义了两个 类 代表一元仿函数 和 二元仿函数 其中 STL 不支持三元仿函数. 只要继承了这两个中的其中一个就拥有了配接能力.
// 一元仿函数
template <typename Arg, typename Result>
struct unary_function {
typedef Arg argument_type;
typedef Result result_type;
};
// 二元仿函数
template <typename Arg1, typename Arg2, typename Result>
struct binary_function {
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};
仿函数 分算术类 关系运算类 逻辑运算类 证同元素(并非STL标准的一员)
- 算术类仿函数共 6 个 加 减 乘 除 模取 否定
- 关系运算类仿函数也是 6个 = != < <= >= >
- 逻辑运算类仿函数三个 and or not
- 证同元素 自身 与证同元素做运算得到自身
- 证同(返回自身 set中使用) 选择 投射 其中投射并没有在 SGI STL中使用