Move Semantics in C++
#include <string> inline std::string& bin(std::string& val) { val.append("Hello C++ Russia!"); return std::move(val); } std::string& goo(std::string& s) { return bin(bin(bin(bin(std::move(s))))); } .string "Hello C++ Russia!" goo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&): push r12 mov esi, OFFSET FLAT:.LC0 mov r12, rdi call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append mov rdi, r12 mov esi, OFFSET FLAT:.LC0 call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append mov rdi, r12 mov esi, OFFSET FLAT:.LC0 call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append mov rdi, r12 mov esi, OFFSET FLAT:.LC0 call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append mov rax, r12 pop r12 ret
A split-screen image shows C++ source code on the left and the resulting assembly output on the right. The code repeatedly applies a function that appends “Hello C++ Russia!” while returning a moved string, but the joke is that move semantics do not eliminate the repeated append operations in the generated code. It is a reaction for discussions about C++ performance, move semantics, and overly optimistic optimization expectations.
- @ithueti / 847 2019-04-19
- Type
- image
- Size
- 800×444 · 41.8 KiB
- Mood
- саркастичный
- Language
- en
- Added