Ru-Brd |
Smart pointer templates are probably the second-most obvious application of templates after container templates; however, the details are far from obvious, as this chapter illustrates. Indeed, many authors cover the topic in some detail. Good material supplementing our discussion can be found in [MeyersMoreEffective], which offers a more basic discussion, and in [AlexandrescuDesign], which describes a complete, policy-based design of a family of smart pointers. The C++ standard library contains a smart pointer template auto_ptr . It is intended for the same use as our Holder / Trule pair of templates, but avoids the use of a second template by exploiting a controversial piece of the C++ overloading rules in the context of variable initialization. [5]
Other smart pointers were proposed for inclusion in the C++ standard library, but the C++ standardization committee decided not to support them. The Boost project offers a library containing a variety of smart pointer classes to meet a variety of needs (see [BoostSmartPtr]). |
Ru-Brd |