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表达式.装饰器内容较多,先简要介绍了装饰器语法,之后详细介绍理解和使用不带参数装饰器时应当注意到的一些细节,然后实现了一个简单的缓存装 ...
随机推荐
- centos7 命令
firewall-cmd --zone=public --add-port=80/tcp --permanent 开启端口 systemctl stop firewalld.service 关闭服务 ...
- 紫书 习题8-18 UVa 11536 (扫描法)
这道题貌似可以用滑动窗口或者单调栈做, 但是我都没有用到. 这道题要求连续子序列中和乘上最小值最大, 那么我们就可以求出每一个元素, 以它为最小值的的最大区间的值, 然后取max就ok了.那么怎么求呢 ...
- 【BZOJ 1083】 [SCOI2005]繁忙的都市
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 很明显的最小生成树了. 输出最后选的那条边就好了. [代码] #include <bits/stdc++.h> usin ...
- 洛谷 P2747 [USACO5.4]周游加拿大Canada Tour
P2747 [USACO5.4]周游加拿大Canada Tour 题目描述 你赢得了一场航空公司举办的比赛,奖品是一张加拿大环游机票.旅行在这家航空公司开放的最西边的城市开始,然后一直自西向东旅行,直 ...
- @SpringBootApplication cannot be resolved to a type In STS
@SpringBootApplication cannot be resolved to a type In STS 学习了:https://stackoverflow.com/questions/4 ...
- drupal7 怎样将一个date字段加入上日期插件效果
//这里以created字段为样例 function Hook_form_alter($form,$form_state,$form_id){ $form['created']['#type'] = ...
- YII进行数据查询及类库追踪
一般处理过程: 模型进行数据操作,继承自CActiveRecord (活跃记录) AR数据库向上的封装.AR通过OOP面向对象方式操作数据库.AR须要终于转变为详细的sql语句.通过一个中间类(cri ...
- Linux平台不同解压缩命令的使用方法
作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...
- node tail 日志服务
var http = require('http'), ,spawn = require('child_process').spawn function onRequest(req, res) { v ...
- uva_11997,K Smallest Sums优先队列
#include<iostream> #include<cstdio> #include<cstring> #include<queue> #inclu ...