mobile wallpaper 1
mobile wallpaper 2
mobile wallpaper 3
mobile wallpaper 4
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
Author
Memki
Published at
2026-10-19
License
CC BY-NC-SA 4.0

Some information may be outdated

Table of Contents