Files
Cpp-in-Embedded-Systems/Chapter06/rvalue_refs.cpp
Amar Mahmutbegovic 0ea2c43f45 add Chapter06
2025-05-08 23:03:25 +02:00

28 lines
626 B
C++

#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;
}