Re: [boost] [contract] move operations and class invariants
Lorenzo Caminiti wrote:
read() can fail, so you can drop its "valid" precondition and just fail when the handle is invalid.
Calling read() on a moved-from object so violating its is_valid() precondition is a bug, not a run-time error while reading the file. The precondition legitimately remains in place to catch bugs, even after it is noted that read() can fail because of file-system or other run-time errors.
On one hand, you want to have a precondition. On the other, you say that if you have the precondition, the class would be crippled and not very useful:
2. How useful is a class like the one above with "crippled" invariants and is_valid() preconditions on all its useful public methods like read()? The answer seems to be: not very useful.
These are contradictory. Either the class that has preconditions is crippled and not very useful, in which case we drop the preconditions as I suggest; or it's useful, in which case we keep them.
participants (1)
-
Peter Dimov