3 ms·
The version without std::move does not call a constructor because of copy elision. The get_display_pixels function constructs the disp_pixels object in place.
by edflsafoiewq 6y ago
The version without std::move does not call a constructor because of copy elision. The get_display_pixels function constructs the disp_pixels object in place.
In the version with std::move, it first copy-elides the function call into a temporary, then move-constructs the disp_pixels object from the temporary. ie as if
auto tmp = emulator.get_display_pixels();
const auto disp_pixels = std::move(tmp); // move constructor called here
// lifetime of tmp ends
So the version with std::move is invoking an extra move-constructor and destructor call.
- iainmerrick 6y agoBut shouldn’t those extra calls be optimized away to nothing, if they don’t have any real side-effects? That’s what I would naively assume.
- edflsafoiewq 6y agoI expect so, yes.