118.类包装器与lambda函数包装器(伪函数实现)
#include <iostream>
#include <list>
using namespace std; //函数包装器,左边参数右边函数
template<class T, class F>
T run(T t, F f)
{
return f(t);
} //先获取类型再执行操作
template<class T>
T runit(T t)
{
//获取伪函数类型
Tfun<decltype(t)> f;
return f(t);
} //创建伪函数
template <class T>
class fun
{
public:
T operator () (T data)
{
return data - ;
}
}; //创建伪函数
template<class T>
class Tfun
{
public:
T operator () (T data)
{
for (auto i : data)
{
cout << i << endl;
}
return data;
}
}; void main()
{
//fun()匿名对象
/*fun<double> x;
cout << run(10.5, fun<double>()) << endl;*/
//cout << run(10.5, x) << endl; list<int> myint;
for (int i = ; i < ; i++)
{
myint.push_back(i);
}
//lambda函数包装器
/*run(myint,[](list<int> myint)->list<int>
{
for (auto i : myint)
{
cout << i << endl;
}
return myint;
});*/ //类包装器
//run(myint, Tfun<list<int>>()); runit(myint);
cin.get();
}
118.类包装器与lambda函数包装器(伪函数实现)的更多相关文章
- python装饰器1:函数装饰器详解
装饰器1:函数装饰器 装饰器2:类装饰器 装饰器3:进阶 先混个眼熟 谁可以作为装饰器(可以将谁编写成装饰器): 函数 方法 实现了__call__的可调用类 装饰器可以去装饰谁(谁可以被装饰): 函 ...
- python 装饰器 (多个装饰器装饰一个函数---装饰器前套一个函数)
#带参数的装饰器 #500个函数 # import time # FLAGE = False # def timmer_out(flag): # def timmer(func): # def inn ...
- Python的lambda函数与排序
Python的lambda函数与排序 2010-03-02 15:02 2809人阅读 评论(0) 收藏 举报 lambdapythonlistlispclass工作 目录(?)[+] 前几天 ...
- Python高手之路【四】python函数装饰器
def outer(func): def inner(): print('hello') print('hello') print('hello') r = func() print('end') p ...
- 智能合约语言 Solidity 教程系列10 - 完全理解函数修改器
这是Solidity教程系列文章第10篇,带大家完全理解Solidity的函数修改器. Solidity系列完整的文章列表请查看分类-Solidity. 写在前面 Solidity 是以太坊智能合约编 ...
- Python高手之路【四】python函数装饰器,迭代器
def outer(func): def inner(): print('hello') print('hello') print('hello') r = func() print('end') p ...
- python语法基础-函数-装饰器-长期维护
######################################################### # 装饰器 # 装饰器非常重要,面试Python的公司必问, # 原则:开放封闭原则 ...
- 谈一下关于C++函数包装问题
在C++中,我们经常遇到在某个特定的时刻,需要将函数进行包装调用,尤其是当我们需要将不同签名的函数放到同一个集合时,由于函数签名不一致导致我们不能直接将各式各样的函数指针放到诸如list这样的集合中, ...
- Python函数小结(2)-- 装饰器、 lambda
本篇依然是一篇学习笔记,文章的结构首先讲装饰器,然后讲lambda表达式.装饰器内容较多,先简要介绍了装饰器语法,之后详细介绍理解和使用不带参数装饰器时应当注意到的一些细节,然后实现了一个简单的缓存装 ...
随机推荐
- windows下matlab代码到ubuntu下中文注释出现乱码
转自:https://blog.csdn.net/kouyi5627/article/details/81513329 环境:Ubuntu18.04,Matlab R2017b. 把matlab文件从 ...
- Linux 文件系统的层次化结构
FHS,Filesystem Hierarchy Standard,文件系统层次化标准.这是一个推荐标准,可以从 http://www.pathname.com/fhs/ 获取. 本文不讨论 FHS, ...
- win系统安装node出现这个2503和2502解决办法
一: 今天在公司的新电脑要安装appium,所以要搭建appium的环境,所以在安装到node的时候,出现了内部错误2503和2502,安装中断. 这种错误可能是权限不足导致,一般“.exe”程序可以 ...
- 洛谷——P2615 神奇的幻方 【Noip2015 day1t1】
https://www.luogu.org/problem/show?pid=2615 题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之 ...
- 在Windows上面安装多个Memcached
在Windows上面安装多个Memcached sc create "memcached Server3" start= auto binPath= "D:\memcac ...
- [React] Refactor a Stateful List Component to a Functional Component with React PowerPlug
In this lesson we'll look at React PowerPlug's <List /> component by refactoring a normal clas ...
- "duplicate symbol for architecture i386" 解决的方法
我在写项目的过程中,碰到了这个错误,我在网上查了一下,发现这个错误的原因是,project里面有反复的类. 解决方式:找到反复的类,然后删除掉就好了. 分析一下, 如图. 能够看出, 错误类型是 du ...
- Android中设置半个屏幕大小且居中的button布局 (layout_weight属性)
先看例如以下布局 :
- Java 深拷贝和浅拷贝 利用序列化实现深拷贝
Java 深拷贝和浅拷贝 转自:http://www.cnblogs.com/mengdd/archive/2013/02/20/2917971.html 深拷贝(deep clone)与浅拷贝(sh ...
- 提高FPGA速度的quartus编译选项
Turning on some optimizations in Quartus II may help increase it. Here are some you may want to try: ...