Debug Move
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include <vector>
#include <optional>
std::vector<int> CreateVec() {
std::vector<int> v { 0, 1, 2, 3, 4 };
std::cout << std::hex << v.data() << '\n';
//return {std::move(v)}; // this one will cause a copy
return (v); // this one moves
//return v; // this one moves as well
}
std::optional<std::vector<int>> CreateOptVec() {
std::vector<int> v { 0, 1, 2, 3, 4 };
std::cout << static_cast<void *>(v.data()) << '\n';
return {v}; // this one will cause a copy
//return v; // this one moves
}
int main() {
std::cout << "CreateVec:\n";
auto vec = CreateVec();
std::cout << static_cast<void *>(vec.data()) << '\n';
std::cout << "CreateOptVec:\n";
auto optVec = CreateOptVec();
std::cout << static_cast<void *>(optVec->data()) << '\n';
}
Enter to Rename, Shift+Enter to Preview