vault backup: 2022-06-08 10:55:41
Affected files: .obsidian/workspace 02. PARA/03. Resources(資源)/C++17/rvalue.md
This commit is contained in:
10
.obsidian/workspace
vendored
10
.obsidian/workspace
vendored
@@ -10,7 +10,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "markdown",
|
"type": "markdown",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "00. TOP/01. TODO.md",
|
"file": "02. PARA/03. Resources(資源)/C++17/rvalue.md",
|
||||||
"mode": "source",
|
"mode": "source",
|
||||||
"source": true
|
"source": true
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outline",
|
"type": "outline",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "00. TOP/01. TODO.md"
|
"file": "02. PARA/03. Resources(資源)/C++17/rvalue.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "backlink",
|
"type": "backlink",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "00. TOP/01. TODO.md",
|
"file": "02. PARA/03. Resources(資源)/C++17/rvalue.md",
|
||||||
"collapseAll": true,
|
"collapseAll": true,
|
||||||
"extraContext": true,
|
"extraContext": true,
|
||||||
"sortOrder": "alphabetical",
|
"sortOrder": "alphabetical",
|
||||||
@@ -125,6 +125,7 @@
|
|||||||
},
|
},
|
||||||
"active": "94f0e8a81af6c9e2",
|
"active": "94f0e8a81af6c9e2",
|
||||||
"lastOpenFiles": [
|
"lastOpenFiles": [
|
||||||
|
"02. PARA/03. Resources(資源)/C++17/rvalue.md",
|
||||||
"00. TOP/01. TODO.md",
|
"00. TOP/01. TODO.md",
|
||||||
"02. PARA/01. Project(專案)/008. Sentinel.md",
|
"02. PARA/01. Project(專案)/008. Sentinel.md",
|
||||||
"02. PARA/03. Resources(資源)/FFMPEG/01. Setup.md",
|
"02. PARA/03. Resources(資源)/FFMPEG/01. Setup.md",
|
||||||
@@ -133,7 +134,6 @@
|
|||||||
"02. PARA/03. Resources(資源)/99. templates/日記.md",
|
"02. PARA/03. Resources(資源)/99. templates/日記.md",
|
||||||
"01. Daily/2022-06-06(週一).md",
|
"01. Daily/2022-06-06(週一).md",
|
||||||
"02. PARA/03. Resources(資源)/Qt.md",
|
"02. PARA/03. Resources(資源)/Qt.md",
|
||||||
"02. PARA/03. Resources(資源)/C++17/智慧指標.md",
|
"02. PARA/03. Resources(資源)/C++17/智慧指標.md"
|
||||||
"02. PARA/04. Archives(歸檔)/01. Project(專案)/004. Group firmware update check.md"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,18 @@
|
|||||||
- 等號右邊的值
|
- 等號右邊的值
|
||||||
- 臨時的值,例如運算的結果
|
- 臨時的值,例如運算的結果
|
||||||
|
- 無法被取址(address-of)的物件
|
||||||
|
|
||||||
# rvalue參考
|
# rvalue參考
|
||||||
可以用兩個`&`來參考rvalue。例如:
|
可以用`&&`來參考rvalue。例如:
|
||||||
```
|
```
|
||||||
int c{5};
|
int c{5};
|
||||||
int&& rtepm {c + 3};
|
int&& rtepm {c + 3};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
關於lvalue、rvalue的分別可以參考[Value categories - cppreference.com](https://en.cppreference.com/w/cpp/language/value_category),或是[rvalue 參考](https://openhome.cc/Gossip/CppGossip/RvalueReference.html)等文章。這邊講用法跟好處。
|
||||||
|
rvalue reference可以減少無間的複製成本。例如:
|
||||||
|
```cpp
|
||||||
|
std::string longStr = "qwertyuiopasdfghjklzxcbnm";
|
||||||
|
std::string anotherLong = longStr;
|
||||||
|
```
|
||||||
|
這時longStr會被複製一份anotherLong,把longStr換成很大的buffer,
|
||||||
Reference in New Issue
Block a user