// 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的更多相关文章

  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. 51nod 1597 有限背包计数问题 (背包 分块)

    题意 题目链接 Sol 不会做啊AAA.. 暴力上肯定是不行的,考虑根号分组 设\(m = \sqrt{n}\) 对于前\(m\)个直接暴力,利用单调队列优化多重背包的思想,按\(\% i\)分组一下 ...

  2. vue的拖拽文件

    <div ref='select_frame' ondragstart="return false">//防止跳转 </div> this.$refs.se ...

  3. select @@identity用法

    用select @@identity得到上一次插入记录时自动产生的ID 如果你使用存储过程的话,将非常简单,代码如下:SET @NewID=@@IDENTITY 说明: 在一条 INSERT.SELE ...

  4. 避免console错误,console兼容

    背景:写js代码时写了很多console.log进行日志打印,最后上生产时不想删除日志输出, 但是ie在不打开控制台时,日志输出会导致后续js不执行,所以需要适时屏蔽js日志输出 (IE等不支持con ...

  5. List的设置值,跟变量的位置关系(变量范围的变化导致结果差别很大)

    我们想要的结果是: [RegnTypeCharge: null,null,null,null,1,null,null,null,null,null,null,null,null,null,null,] ...

  6. Java & COM

  7. Android 获取系统时间和网络时间

    有些时候我们的应用中只能使用网络时间,而不能使用系统的时间,这是为了避免用户关闭了使用网络时间的功能后所产生的误差. 直接上代码. 1.清单文件中网络添加权限. <!-- 访问Internet资 ...

  8. mvc页面间的传值

    本文大致讲解mvc前后端的传值方式,包括control向view.view向control.以及action向action. 回顾 我们回顾下在ASP.NET WebForms中,页面之间最常用的传值 ...

  9. 对synchronized(this)的一些理解

    一.当两个并发线程访问同一个对象object中的这个synchronized(this)同步代码块时,一个时间内只能有一个线程得到执行.另一个线程必须等待当前线程执行完这个代码块以后才能执行该代码块. ...

  10. 设计模式之装饰模式(Decorator)

    1. 装饰者模式,动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更加有弹性的替代方案. 2.组合和继承的区别 继承.继承是给一个类添加行为的比较有效的途径.通过使用继承,可以使得子类在拥有 ...