分类:
2008-09-05 01:55:55
|
References, pointers, and iterators are all handles
|
dangling handles: handles that refer to parts of objects that don't exist any longer
any function that returns a handle to an internal part of the object is dangerous.
[Item29]
|
it's a good policy not to change the status of an object to indicate that something has happened until something actually has.
"copy and swap." In principle, it's very simple. Make a copy of the object you want to modify, then make all needed changes to the copy. If any of the modifying operations throws an exception, the original object remains unchanged.
Forty years ago, goto-laden code was considered perfectly good practice. Now we strive to write structured control flows. Twenty years ago, globally accessible data was considered perfectly good practice. Now we strive to encapsulate data. Ten years ago, writing functions without thinking about the impact of exceptions was considered perfectly good practice. Now we strive to write exception-safe code.
Time goes on. We live. We learn.