zoukankan      html  css  js  c++  java
  • C++ STL 之 内建函数对象

    STL 内建了一些函数对象。分为:算数类函数对象,关系运算类函数对象,逻辑运算类仿函数。这些仿函数所产生的对象,用法和一般函数完全相同,当然我们还可以产生无名的临时对象来履行函数功能。使用内建函数对象,需要引入头文件 #include<functional>。

    6 个算数类函数对象,除了 negate 是一元运算,其他都是二元运算。
    template<class T> T plus<T>//加法仿函数
    template<class T> T minute<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>//取反仿函数
    6 个关系运算类函数对象,每一种都是二元运算。
    template<class T> bool equal_to<T>//等于
    template<class T> bool not_equal_to<T>//不等于
    template<class T> bool greater<T>//大于
    template<class T> bool greater_equal<T>//大于等于
    template<class T> bool less<T>//小于
    template<class T> bool less_equal<T>//小于等于
    逻辑运算类运算函数,not 为一元运算,其余为二元运算。
    template<class T> bool logical_and<T>//逻辑与
    template<class T> bool logical_or<T>//逻辑或
    template<class T> bool logical_not<T>//逻辑非

    #include <iostream>
    #include <functional>
    using namespace std;
    
    int main()
    {
        plus<int> myplus;
        cout << myplus(10, 20) << endl;
        getchar();
        return 0;
    }
  • 相关阅读:
    Subversion 1.5.5 与 Apache 2.2 结合
    IE6 式样表 Bug
    Dreamweaver 禁止自动换行
    错误:Internet Explorer cannot open the Internet site
    Html Agility Pack – XPath 基本语法
    不要安装 CodeSmith 5.2
    控件包含代码块,因此无法修改控件集合
    单例模式
    第一篇博文
    包与导入的概念
  • 原文地址:https://www.cnblogs.com/duxie/p/10939677.html
Copyright © 2011-2022 走看看