Update item25.md

This commit is contained in:
猫耳堀川雷鼓 2021-03-15 19:58:40 +08:00 committed by GitHub
parent e5a611b14e
commit 529954b11f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -151,7 +151,7 @@ operator+(Matrix&& lhs, const Matrix& rhs)
如果`Matrix`不支持移动操作,将其转换为右值不会变差,因为右值可以直接被`Matrix`的拷贝构造函数拷贝(见[Item23](https://github.com/kelthuzadx/EffectiveModernCppChinese/blob/master/5.RRefMovSemPerfForw/item23.md))。如果`Matrix`随后支持了移动操作,`operator+`将在下一次编译时受益。就是这种情况,通过将`std::move`应用到按值返回的函数中要返回的右值引用上,不会损失什么(还可能获得收益)。
使用通用引用和`std::forward`的情况类似。考虑函数模板`reduceAndCopy`收到一个未折叠unreduced对象`Fraction`,将其折叠,并返回一个折叠后的副本。如果原始对象是右值,可以将其移动到返回值中(避免拷贝开销),但是如果原始对象是左值,必须创建副本,因此如下代码:
使用通用引用和`std::forward`的情况类似。考虑函数模板`reduceAndCopy`收到一个未规约unreduced对象`Fraction`,将其规约,并返回一个规约后的副本。如果原始对象是右值,可以将其移动到返回值中(避免拷贝开销),但是如果原始对象是左值,必须创建副本,因此如下代码:
```cpp
template<typename T>