chromium之tuple
- // A Tuple is a generic templatized container, similar in concept to std::pair.
- // There are classes Tuple0 to Tuple6, cooresponding to the number of elements
- // it contains. The convenient MakeTuple() function takes 0 to 6 arguments,
- // and will construct and return the appropriate Tuple object. The functions
- // DispatchToMethod and DispatchToFunction take a function pointer or instance
- // and method pointer, and unpack a tuple into arguments to the call.
- //
- // Tuple elements are copied by value, and stored in the tuple. See the unit
- // tests for more details of how/when the values are copied.
- //
- // Example usage:
- // // These two methods of creating a Tuple are identical.
- // Tuple2<int, const char*> tuple_a(1, "wee");
- // Tuple2<int, const char*> tuple_b = MakeTuple(1, "wee");
- //
- // void SomeFunc(int a, const char* b) { }
- // DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
- // DispatchToFunction(
- // &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo")
- //
- // struct { void SomeMeth(int a, int b, int c) { } } foo;
- // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
- // // foo->SomeMeth(1, 2, 3);
Tuple是一个通用的模板化容器,类似std::pair的概念。
转换函数MakeTuple接收0-6个参数,并返回一个Tuple对象
- DispatchToFunction 接收一个函数指针,并解压一个tuple作为函数指针的参数,并调用
- // void SomeFunc(int a, const char* b) { }
- // DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
- DispatchToMethod 接收一个实例、实例的方法指针,并解压一个tuple作为函数指针的参数,并调用
- // struct { void SomeMeth(int a, int b, int c) { } } foo;
- // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
看看代码
- template <class P>
- struct TupleTraits {
- typedef P ValueType;
- typedef P& RefType;
- typedef const P& ParamType;
- };
- template <class P>
- struct TupleTraits<P&> {
- typedef P ValueType;
- typedef P& RefType;
- typedef P& ParamType;
- };
- template <class A>
- struct Tuple1 {
- public:
- typedef A TypeA;
- typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
- typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
- typedef Tuple1<typename TupleTraits<A>::ParamType> ParamTuple;
- Tuple1() {}
- explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {}
- A a;
- };
- template <class Function, class A>
- inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
- (*function)(arg.a);
- }
chromium之tuple的更多相关文章
- chromium之task
// A task is a generic runnable thingy, usually used for running code on a // different thread or fo ...
- [原创]chromium源码阅读-进程间通信IPC.消息的接收与应答
chromium源码阅读-进程间通信IPC.消息的接收与应答 chromium源码阅读-进程间通信IPC.消息的接收与应答 介绍 chromium进程间通信在win32下是通过命名管道的方式实现的 ...
- QT5利用chromium内核与HTML页面交互
在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...
- 【.NET深呼吸】元组数据(Tuple)
各位观众,大家好,欢迎收看由火星电视台直播的<老周吹牛>节目,注意:本节目没有任何技术含量,如果您没有兴趣,请砸掉电视机. 今天说一下System命名空间下的一个数据类型——Tuple,翻 ...
- python之最强王者(7)——元组(tuple)
1.序列(sequence): 说明:在前面的字符串列表中其实我们已经用到了序列,之所以放到这篇来讲主要是为了承上启下,方便理解和记忆. python的数据访问模型:直接存取 ,序列 ,映射 对非容器 ...
- tuple放入dict中
tuple放入dict中是否可以正常运行 # 将tuple放入dict中 a = ('AI','Kobe','Yao') b = ('AI',['Kobe','Yao']) dict1 = {'a': ...
- list,tuple,dict,set常用方法
Python中list,tuple,dict,set常用方法 collections模块提供的其它有用扩展类型 from collections import Counter from collect ...
- Python中内置数据类型list,tuple,dict,set的区别和用法
Python中内置数据类型list,tuple,dict,set的区别和用法 Python语言简洁明了,可以用较少的代码实现同样的功能.这其中Python的四个内置数据类型功不可没,他们即是list, ...
- Google之Chromium浏览器源码学习——base公共通用库(一)
Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...
随机推荐
- stark——查看页面编辑删除按钮
一.数据列表 设计查页面,主要展示两部分内容,表头部分和数据部分, 表头通过遍历list_display和默认要显示的编辑和删除字段. 1.数据构建 (1)service/stark.py,后台数据构 ...
- 洛谷P1730 最小密度路径(floyd)
题意 题目链接 Sol zz floyd. 很显然的一个dp方程\(f[i][j][k][l]\)表示从\(i\)到\(j\)经过了\(k\)条边的最小权值 可以证明最优路径的长度一定\(\leqsl ...
- axios 发 post 请求,后端接收不到参数的解决方案
问题场景 场景很简单,就是一个正常 axios post 请求: axios({ headers: { 'deviceCode': 'A95ZEF1-47B5-AC90BF3' }, method: ...
- Flexviewer使用Google地图作为底图
Flexviewer使用Google地图作为底图: 在使用google地图作底图前提是你需要在Flex中实现加载google地图的代码(网上一大堆,随便找), 在只加载google地图的情况下,成功显 ...
- java原生文件打包
一.背景 前端时间,自己做的项目需要打包功能,不想再引外部的jar包 便用java.util.zip做了下该功能 二.适用场景 生成多个word.excel.xml等文件,并要求打包下载的情形 例:项 ...
- <meta name="viewport" content="width=device-width, initial-scale=1.0">理解
ViewPort <meta>标记用于指定用户是否可以缩放Web页面,如果可以,那么缩放到的最大和最小缩放比例是什么.使用ViewPort <meta>标记还表示文档针对移动设 ...
- .NET部分知识点整理
.Net学习 Visual Studio2018 企业版:NJVYC-BMHX2-G77MM-4XJMR-6Q8QF 专业版:KBJFW-NXHK6-W4WJM-CRMQB-G3CDH 开发工具常用V ...
- python操作excel (openpyxl)
最近看到好几次群里有人问xlwt.wlrd的问题,怎么说呢,如果是office2007刚出来,大家用xlsx文件用不习惯,还可以理解,这都10年过去了喂,就算没有进化到office2016,还在用of ...
- 安装PYTHON PIL包
安装pillow而不是PIL pip install pillow 参考: https://github.com/python-pillow/Pillow
- (转)sizeof()和_countof()
(转)sizeof()和_countof() 先看程序: #include <iostream> using namespace std; int main(int argc, cha ...