add Chapter06

This commit is contained in:
Amar Mahmutbegovic
2025-05-08 23:01:29 +02:00
parent 7dab196517
commit 0ea2c43f45
8 changed files with 222 additions and 0 deletions

27
Chapter06/rvalue_refs.cpp Normal file
View File

@@ -0,0 +1,27 @@
#include <string>
#include <vector>
#include <cstdio>
int main()
{
std::string str = "Hello world, this is move semantics demo!!!";
printf("str.data address is %p\r\n", (void*)str.data());
std::vector<std::string> v;
v.push_back(str);
printf("str after copy is <%s>\r\n", str.data());
v.push_back(std::move(str));
//v.push_back(static_cast<std::string&&>(str));
printf("str after move is <%s>\r\n", str.data());
for(const auto & s:v) {
printf("s is <%s>\r\n", s.data());
printf("s.data address is %p\r\n", (void*)s.data());
}
return 0;
}