标准库定义的函数对象
2017-04-08 12:01
253 查看
//标准库定义的函数对象
#include<iostream>
#include<functional>
using namespace std;
int main()
{
//算术
//加法 plus<Type>
plus<int> a;
int sum = a(10,20);
cout << "Plus is "<< sum << endl;
//减法 minus<Type>
minus<int> b;
int minus = b(10, 20);
cout << "Minus is " << minus << endl;
//乘法 multiplies<Type>
multiplies<int> c;
int multiplies = c(10, 20);
cout << "Multiplies is " << multiplies << endl;
//除法 divides<Type>
divides<int> d;
int divides = d(10, 10);
cout << "Divides is " << divides << endl;
//取余 modulus<Type>
modulus<int> e;
int modulus = e(30, 30);
cout << "Modulus is " << modulus << endl;
//取反 negate<Type>
negate<int> f;
int negate = f(20);
cout << "Negate is " << negate << endl;
//关系
//相等 equal_to<Type>
equal_to<int> g;
if (g(20, 20))
cout << "It's Equal" << endl;
//不相等 not_equal_to<Type>
not_equal_to<int> j;
if (j(20, 10))
cout << "It's Not Equal" << endl;
//大于 greater<Type>
greater<int> k;
if (k(20, 10))
cout << "The First More than Second" << endl;
//大于等于 greater_equal<Type>
greater_equal<int> h;
if (h(20, 20))
cout << "The First is More than and equal to Second" << endl;
//小于 less<Type>
less<int> m;
if (m(10, 20))
cout << "The First is less than Second" << endl;
//小于等于 les_equal<Type>
less_equal<int> n;
if (n(20, 20))
cout << "The First is less than and equal to Second" << endl;
//逻辑
//且 logical_and<Type>
logical_and<int> v;
cout << "m ,n and is " << v(m(10, 20), n(20, 30)) << endl;
//或 logical_or<Type>
logical_or<int> l;
cout << "m ,n or is " << l(m(10, 20), n(20, 30)) << endl;
//非 loogical_not<Type>
logical_not<int> w;
cout << "m ,n not is " << w(l(m(10, 20), n(20, 30))) << endl;
system("pause");
return 0;
}
#include<iostream>
#include<functional>
using namespace std;
int main()
{
//算术
//加法 plus<Type>
plus<int> a;
int sum = a(10,20);
cout << "Plus is "<< sum << endl;
//减法 minus<Type>
minus<int> b;
int minus = b(10, 20);
cout << "Minus is " << minus << endl;
//乘法 multiplies<Type>
multiplies<int> c;
int multiplies = c(10, 20);
cout << "Multiplies is " << multiplies << endl;
//除法 divides<Type>
divides<int> d;
int divides = d(10, 10);
cout << "Divides is " << divides << endl;
//取余 modulus<Type>
modulus<int> e;
int modulus = e(30, 30);
cout << "Modulus is " << modulus << endl;
//取反 negate<Type>
negate<int> f;
int negate = f(20);
cout << "Negate is " << negate << endl;
//关系
//相等 equal_to<Type>
equal_to<int> g;
if (g(20, 20))
cout << "It's Equal" << endl;
//不相等 not_equal_to<Type>
not_equal_to<int> j;
if (j(20, 10))
cout << "It's Not Equal" << endl;
//大于 greater<Type>
greater<int> k;
if (k(20, 10))
cout << "The First More than Second" << endl;
//大于等于 greater_equal<Type>
greater_equal<int> h;
if (h(20, 20))
cout << "The First is More than and equal to Second" << endl;
//小于 less<Type>
less<int> m;
if (m(10, 20))
cout << "The First is less than Second" << endl;
//小于等于 les_equal<Type>
less_equal<int> n;
if (n(20, 20))
cout << "The First is less than and equal to Second" << endl;
//逻辑
//且 logical_and<Type>
logical_and<int> v;
cout << "m ,n and is " << v(m(10, 20), n(20, 30)) << endl;
//或 logical_or<Type>
logical_or<int> l;
cout << "m ,n or is " << l(m(10, 20), n(20, 30)) << endl;
//非 loogical_not<Type>
logical_not<int> w;
cout << "m ,n not is " << w(l(m(10, 20), n(20, 30))) << endl;
system("pause");
return 0;
}
相关文章推荐
- C++ Primer 学习笔记:标准库定义的函数对象
- 标准库定义的函数对象--接“将函数对象用于标准库算法”
- C++ Pirmer : 第十四章 : 重载运算符与类型转换之函数调用运算符与标准库的定义的函数对象
- Oracle 查看 表 存储过程 触发器 函数 等对象定义语句的方法
- 使用sys.SQL_Modules获取SQL Server数据库对象(存储过程,视图,函数)定义脚本
- 静态函数里定义的变量,不为所有对象共享,类的静态变量和类外全局变量区别,静态函数和普通函数区别
- C++中自己定义函数对象
- 将函数对象用于标准库算法
- Oracle 查看 表 存储过程 触发器 函数 等对象定义语句的方法
- Oracle 查看 表 存储过程 触发器 函数 等对象定义语句的方法
- 获取 XMLDocument对象 和 XMLHttpRequest 对象的函数定义
- 使用定义Prototype的对象或函数
- (zz)定义函数对象
- Oracle 查看 表 存储过程 触发器 函数 等对象定义语句的方法
- JavaScript基础(对象定义,函数定义,数据类型等)
- Oracle 查看 表 存储过程 触发器 函数 等对象定义语句的方法
- JavaScript中的函数、类对象、类的定义
- Oracle 查看 表 存储过程 触发器 函数 等对象定义语句的方法
- Oracle 查看 表 存储过程 触发器 函数 等对象定义语句的方法
- js 多种变量定义(对象直接量,数组直接量和函数直接量)