2016年11月8日
摘要: Then what's really happening is TWO different sections of memory are being allocated. It's done at one time, but it's two "logical" blocks. One is the 阅读全文
posted @ 2016-11-08 18:01 abelian 阅读(229) 评论(0) 推荐(0)
摘要: 装饰器本质上是一个Python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象。它经常用于有切面需求的场景,比如:插入日志、性能测试、事务处理、缓存、权限校验等场景。装饰器是解决这类问题的绝佳设计,有了装饰器,我们就可以抽离出大量与函数功能本身无关的雷 阅读全文
posted @ 2016-11-08 11:20 abelian 阅读(118) 评论(0) 推荐(0)
  2016年11月6日
摘要: #include <type_traits> #include <utility> struct A {}; struct B {}; struct C {}; void func(A, const C&, B) {} template<typename func_return_type, type 阅读全文
posted @ 2016-11-06 13:10 abelian 阅读(144) 评论(0) 推荐(0)
  2016年11月4日
摘要: 所有的具名变量或对象都是左值,而匿名变量则是右值. 右值引用类型是独立于值的,一个右值引用参数作为函数的形参,在函数内部再转发该参数的时候它已经变成一个左值了,并不是它原来的类型了。 在 C++11 之前,右值是不能被引用的,最大限度就是用常量引用绑定一个右值,如 : const int &a = 阅读全文
posted @ 2016-11-04 11:40 abelian 阅读(279) 评论(0) 推荐(0)
  2016年11月2日
摘要: void test(string &tmp) // lvalue { dout<<"string& fun:"<<tmp<<endl; } template<typename T> void test(T& para, typename std::enable_if<std::is_same<T, 阅读全文
posted @ 2016-11-02 19:40 abelian 阅读(94) 评论(0) 推荐(0)
摘要: 一般的教材上讲到引用时,都是说“引用是对象的一个别名”。我认为这种定义是不清晰的,不利于初学者理解引用。至少我自己曾经被这个定义困扰了一段时间。到底什么是“别名”? 实际上,引用的实质是位于xxxxxx地址上的一个xxxx类型的对象。比如教科书上常用的例子: int a = 5; //不妨假设编译器 阅读全文
posted @ 2016-11-02 17:00 abelian 阅读(165) 评论(0) 推荐(0)
摘要: 1 左值指的是可以取地址的变量,右值指的是非左值. 二者的根本区别在于能否获取内存地址,能否赋值不是区分的依据. 通常临时量均为右值. 2 C++03标准中只有const左值引用与non-const左值引用. a) const左值引用即常量左值引用,表现形式为:cosnt T & b) non-co 阅读全文
posted @ 2016-11-02 16:16 abelian 阅读(123) 评论(0) 推荐(0)
摘要: 在C++中,下面三种对象需要调用拷贝构造函数(有时也称“复制构造函数”): 1) 一个对象作为函数参数,以值传递的方式传入函数体; 2) 一个对象作为函数返回值,以值传递的方式从函数返回; 3) 一个对象用于给另外一个对象进行初始化(常称为复制初始化); 临时对象大多数会被编译器优化掉的(RVO), 阅读全文
posted @ 2016-11-02 15:49 abelian 阅读(166) 评论(0) 推荐(0)
摘要: PT expr PT结果 T T& int int& int T& int& int& int T& const int const int& const int T& const int& const int& const int T& int* int *& int* T& const int* 阅读全文
posted @ 2016-11-02 15:39 abelian 阅读(178) 评论(0) 推荐(0)
摘要: std::result_of 模板参数只能是函数指针类型,函数引用类型,function-like class(仿函数类)三者之一;不能是函数类型,函数数类型是不具有调用call特性的. result_of内部是把函数调用拆成函数类型和函数参数两部分处理的int fn(int) {return in 阅读全文
posted @ 2016-11-02 15:37 abelian 阅读(718) 评论(0) 推荐(1)