4 ms·
Copy elision + move semantics can be quite confusing at first in C++. For example at times explicitly calling move can be less efficient than implicitly relying
by shmerl 11y ago
Copy elision + move semantics can be quite confusing at first in C++. For example at times explicitly calling move can be less efficient than implicitly relying on copy elision.
Another good read: http://en.cppreference.com/w/cpp/language/copy_elision http://en.cppreference.com/w/cpp/language/copy_elision
- kentonv 11y ago> explicitly calling move can be less efficient than implicitly relying on copy elision Sure, in the sense that non-zero is greater than zero. But move constructors are almost always basically a memcpy() sometimes followed by some zeroing of the old data, never heap allocation nor expensive atomic ops. IMO it's not worth worrying about. Much better to accidentally invoke a redundant move because you specified std::move() when you didn't have to than to accidentally invoke a redundant copy because you thought RVO would kick in but it didn't.
- shmerl 11y agoThat may be, though code becomes more cluttered with moves as well.