- 博客(5)
- 收藏
- 关注
原创 Item 30:Familiarize yourself with perfect forwarding failure cases
Item 30:Familiarize yourself with perfect forwarding failure cases情况1:情况2:情况3: 完美转发不仅仅是转发对象,而且还转发对象的修饰,无论是左值右值还是const或者volatile。但是完美转发也有失效的时候。 情况1: template<typename T> void fwd(T&& para...
2019-04-02 09:11:43
268
原创 Item 29:Assume that move operations are not present, not cheap, and not used.
Item 29:Assume that move operations are not present, not cheap, and not used. Move 并不是万能的,在一些特定的情况下使用move 关键字,实际上并没有使用所期待的操作,或者并没有想象中的节省。 例如stl 库中,当使用 std::vector 的时候,move的花费就很低,因为这种容器会有一个唯一的指针指向它,mov...
2019-03-18 04:41:43
202
原创 Item 28: Understand reference collapsing.
Item 28: Understand reference collapsing. 引用折叠。 不同的引用是不能同时使用的。例如: Widget& && w 是非法的。但是在特定情况下,引用是可以折叠的。 首先一个知识点: 在使用模板函数的时候 template<typename T> void func(T&& param) C++的编码...
2019-03-13 09:08:33
200
原创 Item 27: Familiarize yourself with alternatives to overloading on universal references
Item 27: Familiarize yourself with alternatives to overloading on universal references (Effective Modern C++ 读书笔记) 这一章主要解决Item 26的问题。 解决方法,使用信号调度(Use flag dispatch) 先来解决如下例子: std::multiset&lt;std::str...
2019-03-10 10:35:18
232
原创 Item 26: Avoid overloading on universal reference (Effective Modern C++ 读书笔记)
Item 26: Avoid overloading on universal reference 之前看书看到了25,决定写读书笔记,所以从26开始,全书完本后回补之前的。写笔记感觉比只看书效果好很多,虽然用了更多时间,但是确实非常有收获。开始正题。 上例子: std::multiset&amp;lt;std::string&amp;gt; names; void logAndAdd(const std::s...
2019-03-08 23:28:47
281
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅