Item 25
Avoid returning handles(references, pointers, or iterators) to object internals. It increases encapsulation, helps const
member functions act const
, and minimizes the creation of dangling handles.
Item 26
1. Functions offering the basic guarantee promise that if an exception is thrown, everything in the program remains in a valid state.
2. Functions offering the strong guarantee promise that if an exception is thrown, the state of the program is unchanged.
3. Functions offering the nothrow guarantee promise never to throw exceptions, because they always do what they promise to do.
- Exception-safe functions leak no resources and allow no data structures to become corrupted, even when exceptions are thrown. Such functions offer the basi, strong, or nothrow guarantees.
- The strong guarantee can often be implemented via
copy-and-swap
,but the strong guarantee is not practical for all functions. - A function can usually offer a guarantee no stronger than the weakest guarantee of the functions it calls.
Item 27
1. Limit most inlining to small, frequently called functions. This facilitates debugging and binary upgradability, minimizes potential code bloat, and maximizes the chances of greater program speed.
2. Don’t declare function templates inline
just because they appear in header files.
Item 28
1. The general idea behind minimizing compilation dependencies is to depend on declarations instead of definitions. Two approached based on this idea are Handle classed and Interface classed.
2. Library header files should exist in full and declaration-only forms. This applies regardless of whether templates are involved.