On 29/05/2017 19:36, Andrzej Krzemienski wrote:
Ok, so who of the people who are following this thread ever did anything else with these past-removal objects, other than to destroy them? I am not being sarcastic. I just can't imagine anyone doing anything else with them.
Reassignment is pretty common. Think of an array or queue where items are moved in and out of slots. It's perfectly legal to do this with move-assignment directly of T, not just of a storage abstraction (unless you're an AllocatorAwareContainer, I guess). Though it's important to realise that unless you know the type in question you can't rely on it itself having a perceptible empty state -- if you want to track which slots are used or not then you might need to do that separately. It's always legal for an arbitrary type to copy itself even if you ask it to move. Perhaps this counts as a special case of destruction, though. For types that do have a well-defined empty state (like most smart pointers) it can be safer to make assumptions that the pointer is now empty after being moved-from. (As long as you remember that it's up to both the method you're passing the object to and the object itself whether the move actually happens -- calling std::move by itself is a declaration of intent, not an action. That trips many people up at first.)