|
|
|
|
|
by lultimouomo
3997 days ago
|
|
You're right; s/undefined/unspecified/. The comment on the article still stands though. You're still invoking unspecified behaviour, and this is a horrible practice - it forces you to take not on which classes you are sure of the actual behaviour when accessing after move, and you're bound to slip. (Note that the article itself uncorrectly says that move leaves string in an invalid state, which is what threw me off track) |
|
"By stealing the string, we put foo in an invalid state".
foo is an object of the SetStringer class. It puts it an in invalid state because it no longer maintains its own invariants.
The whole point of this article is about how you can move member variables for efficiency, while ensuring the owning object is left in a valid state (as move/rvalue semantics require).
Wanting to be able to move a member variable is no stranger than wanting to move the object itself; in that sense an rvalue ref overloaded getter is no stranger than move construction/assignment, it's just more rare because it's less used.