1. // A Tuple is a generic templatized container, similar in concept to std::pair.
  2. // There are classes Tuple0 to Tuple6, cooresponding to the number of elements
  3. // it contains. The convenient MakeTuple() function takes 0 to 6 arguments,
  4. // and will construct and return the appropriate Tuple object. The functions
  5. // DispatchToMethod and DispatchToFunction take a function pointer or instance
  6. // and method pointer, and unpack a tuple into arguments to the call.
  7. //
  8. // Tuple elements are copied by value, and stored in the tuple. See the unit
  9. // tests for more details of how/when the values are copied.
  10. //
  11. // Example usage:
  12. // // These two methods of creating a Tuple are identical.
  13. // Tuple2<int, const char*> tuple_a(1, "wee");
  14. // Tuple2<int, const char*> tuple_b = MakeTuple(1, "wee");
  15. //
  16. // void SomeFunc(int a, const char* b) { }
  17. // DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
  18. // DispatchToFunction(
  19. // &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo")
  20. //
  21. // struct { void SomeMeth(int a, int b, int c) { } } foo;
  22. // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
  23. // // foo->SomeMeth(1, 2, 3);

Tuple是一个通用的模板化容器,类似std::pair的概念。

转换函数MakeTuple接收0-6个参数,并返回一个Tuple对象

  1. DispatchToFunction 接收一个函数指针,并解压一个tuple作为函数指针的参数,并调用
  1. // void SomeFunc(int a, const char* b) { }
  2. // DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
  1. DispatchToMethod 接收一个实例、实例的方法指针,并解压一个tuple作为函数指针的参数,并调用
  1. // struct { void SomeMeth(int a, int b, int c) { } } foo;
  2. // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));

看看代码

  1. template <class P>
  2. struct TupleTraits {
  3. typedef P ValueType;
  4. typedef P& RefType;
  5. typedef const P& ParamType;
  6. };
  7.  
  8. template <class P>
  9. struct TupleTraits<P&> {
  10. typedef P ValueType;
  11. typedef P& RefType;
  12. typedef P& ParamType;
  13. };
  14.  
  15. template <class A>
  16. struct Tuple1 {
  17. public:
  18. typedef A TypeA;
  19. typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
  20. typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
  21. typedef Tuple1<typename TupleTraits<A>::ParamType> ParamTuple;
  22.  
  23. Tuple1() {}
  24. explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {}
  25.  
  26. A a;
  27. };
  28.  
  29. template <class Function, class A>
  30. inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
  31. (*function)(arg.a);
  32. }

chromium之tuple的更多相关文章

  1. chromium之task

    // A task is a generic runnable thingy, usually used for running code on a // different thread or fo ...

  2. [原创]chromium源码阅读-进程间通信IPC.消息的接收与应答

    chromium源码阅读-进程间通信IPC.消息的接收与应答   chromium源码阅读-进程间通信IPC.消息的接收与应答 介绍 chromium进程间通信在win32下是通过命名管道的方式实现的 ...

  3. QT5利用chromium内核与HTML页面交互

    在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...

  4. 【.NET深呼吸】元组数据(Tuple)

    各位观众,大家好,欢迎收看由火星电视台直播的<老周吹牛>节目,注意:本节目没有任何技术含量,如果您没有兴趣,请砸掉电视机. 今天说一下System命名空间下的一个数据类型——Tuple,翻 ...

  5. python之最强王者(7)——元组(tuple)

    1.序列(sequence): 说明:在前面的字符串列表中其实我们已经用到了序列,之所以放到这篇来讲主要是为了承上启下,方便理解和记忆. python的数据访问模型:直接存取 ,序列 ,映射 对非容器 ...

  6. tuple放入dict中

    tuple放入dict中是否可以正常运行 # 将tuple放入dict中 a = ('AI','Kobe','Yao') b = ('AI',['Kobe','Yao']) dict1 = {'a': ...

  7. list,tuple,dict,set常用方法

    Python中list,tuple,dict,set常用方法 collections模块提供的其它有用扩展类型 from collections import Counter from collect ...

  8. Python中内置数据类型list,tuple,dict,set的区别和用法

    Python中内置数据类型list,tuple,dict,set的区别和用法 Python语言简洁明了,可以用较少的代码实现同样的功能.这其中Python的四个内置数据类型功不可没,他们即是list, ...

  9. Google之Chromium浏览器源码学习——base公共通用库(一)

    Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...

随机推荐

  1. stark——查看页面编辑删除按钮

    一.数据列表 设计查页面,主要展示两部分内容,表头部分和数据部分, 表头通过遍历list_display和默认要显示的编辑和删除字段. 1.数据构建 (1)service/stark.py,后台数据构 ...

  2. 洛谷P1730 最小密度路径(floyd)

    题意 题目链接 Sol zz floyd. 很显然的一个dp方程\(f[i][j][k][l]\)表示从\(i\)到\(j\)经过了\(k\)条边的最小权值 可以证明最优路径的长度一定\(\leqsl ...

  3. axios 发 post 请求,后端接收不到参数的解决方案

    问题场景 场景很简单,就是一个正常 axios post 请求: axios({ headers: { 'deviceCode': 'A95ZEF1-47B5-AC90BF3' }, method: ...

  4. Flexviewer使用Google地图作为底图

    Flexviewer使用Google地图作为底图: 在使用google地图作底图前提是你需要在Flex中实现加载google地图的代码(网上一大堆,随便找), 在只加载google地图的情况下,成功显 ...

  5. java原生文件打包

    一.背景 前端时间,自己做的项目需要打包功能,不想再引外部的jar包 便用java.util.zip做了下该功能 二.适用场景 生成多个word.excel.xml等文件,并要求打包下载的情形 例:项 ...

  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">理解

    ViewPort <meta>标记用于指定用户是否可以缩放Web页面,如果可以,那么缩放到的最大和最小缩放比例是什么.使用ViewPort <meta>标记还表示文档针对移动设 ...

  7. .NET部分知识点整理

    .Net学习 Visual Studio2018 企业版:NJVYC-BMHX2-G77MM-4XJMR-6Q8QF 专业版:KBJFW-NXHK6-W4WJM-CRMQB-G3CDH 开发工具常用V ...

  8. python操作excel (openpyxl)

    最近看到好几次群里有人问xlwt.wlrd的问题,怎么说呢,如果是office2007刚出来,大家用xlsx文件用不习惯,还可以理解,这都10年过去了喂,就算没有进化到office2016,还在用of ...

  9. 安装PYTHON PIL包

    安装pillow而不是PIL pip install pillow 参考: https://github.com/python-pillow/Pillow

  10. (转)sizeof()和_countof()

    (转)sizeof()和_countof()   先看程序: #include <iostream> using namespace std; int main(int argc, cha ...