fix typo; add xmind (#63)

Co-authored-by: johnwdjiang <johnwdjiang@tencent.com>
This commit is contained in:
David 2020-12-22 13:20:48 +08:00 committed by GitHub
parent 6ade27f0aa
commit 0c413c0072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -34,7 +34,7 @@ typename remove_reference<T>::type&&
move(T&& param)
{
using ReturnType = // alias declaration;
typename remove_reference<T>::type&&; // Item 9
typename remove_reference<T>::type&&; // see Item 9
return static_cast<ReturnType>(param);
}
@ -188,6 +188,11 @@ public:
+ `std::forward`只有当它的参数被绑定到一个右值时,才将参数转换为右值。
+ `std::move`和`std::forward`在运行期什么也不做。
### 参考问题(非书籍内容)
关于move语义的解释
https://stackoverflow.com/questions/36827900/what-makes-moving-objects-faster-than-copying

View File

@ -72,7 +72,7 @@ logAndAdd(22); // calls int overload
```cpp
short nameIdx;
...
... // give nameIdx a value
logAndAdd(nameIdx); // error!
```
@ -84,7 +84,7 @@ logAndAdd(nameIdx); // error!
使用通用引用类型的函数在C++中是贪婪函数。他们几乎可以精确匹配任何类型的参数极少不适用的类型在Item 30中介绍。这也是组合重载和通用引用使用是糟糕主意的原因通用引用的实现会匹配比开发者预期要多得多的参数类型。
一个更容易入这种陷阱的例子是完美转发构造函数。简单对`logAndAdd`例子进行改造就可以说明这个问题。将使用`std::string`类型改为自定义`Person`类型即可:
一个更容易入这种陷阱的例子是完美转发构造函数。简单对`logAndAdd`例子进行改造就可以说明这个问题。将使用`std::string`类型改为自定义`Person`类型即可:
```cpp
class Person

BIN
EffectModernC++.xmind Normal file

Binary file not shown.