151 words
1 minute
内建函数对象 - CPP STL
内建函数对象意义
概念
- STL内建了一些函数对象
分类
- 算术仿函数
- 关系仿函数
- 逻辑仿函数
用法
- 这些仿函数所产生的对象,用法和一般函数完全相同
- 使用内建函数对象,需引入
#include <functional>
算术仿函数
功能描述
- 实现四则运算
- 其中negate是一元运算,其他都是二元运算
仿函数原型
template<class T> T plus<T>; //加法仿函数template<class T> T minus<T>; //减法template<class T> T multiplies<T>;//乘法template<class T> T divides<T>; //除法template<class T> T modulus<T>; //取模(余)template<class T> T negate<T>; //取反 10 -> -10关系仿函数
功能描述
- 实现关系对比
仿函数原型
template<class T> T bool equal_to<T>template<class T> T bool not_equal<T>template<class T> T bool greater<T>template<class T> T bool greater_equal<T>template<class T> T bool less<T>template<class T> T bool less_equal<T>逻辑仿函数
功能描述
- 实现逻辑运算
函数原型
template<class T> bool logical_and<T> //与 同真为真template<class T> bool logical_or<T> //或 同假为假template<class T> bool logical_not<T> //非 真为假,假为真Video
Share
If this article helped you, please share it with others!
内建函数对象 - CPP STL
https://www.bilibili.com/video/BV1et411b73Z/?p=240 Some information may be outdated
Related Posts Smart