std::move was probably one of the most confusing additions to C++ 11. It doesn’t even move anything and is just a glorified static_cast, after all. Because of this I always thought of it as a way to transfer (move) ownership, which is invaluable for communicating intent. Ownership transfer has an interesting side-effect though - it enables new owners to reuse the guts of “gifted” instance instead of using defensive copying. For example, in case of std::string, we can reuse the heap-allocated array of characters without unnecessary copies.
Oh well, things are always great in theory, but what about practice? Let’s check
and the results do not disappoint and a cleaner version that explicitly releases ownership of the s after first copy is 1.4X faster than its copy-only sibling
I always recommend writing explicit code and now in addition to handwavy “clean code” argument I can also back up my recommendation with performance improvements.