2 ms·
I'm not sure I would say that "valid" and "useful" are the same. Things that must be safe after moving: destructing, assigning. No other operation need make sen
by forrestthewoods 2y ago
I'm not sure I would say that "valid" and "useful" are the same. Things that must be safe after moving: destructing, assigning. No other operation need make sense.
It sucks that C++ can't enforce "don't use struct after moving". It's definitely a wart, of which C++ has no shortage. But you can still get away with no default constructor and not having to sprinkle a kajillion "isUseful" checks around your codebase.
Code can assume the struct is useful. The case where it's not is rare and probably won't ever come up. Such is life when writing C++!
- nemetroid 2y ago> I'm not sure I would say that "valid" and "useful" are the same. In standardese, they are: an object in a "valid but unspecified state" requires "that the object’s invariants are met and operations on the object behave as specified for its type"[1]. In other words, any operation without preconditions may be performed. > Things that must be safe after moving: destructing, assigning. No other operation need make sense. That's not accurate for standard library types: moved-from objects must be in a "valid but unspecified state"[2]. 1: C++23 working draft, 3.66 valid but unspecified state [defns.valid] 2: C++23 working draft, 16.4.6.15 Moved-from state of library types [lib.types.movedfrom]