Boost logo

Boost :

From: Tobias Schwinger (schwinger_at_[hidden])
Date: 2003-09-23 18:19:12


The boost library contains a fine set of smart pointer templates.

I noticed that the design could be optimized towards flexibility and better
source code maintainance by parametrizing the template
with another type to decouple the deletion behavior from the smart pointer
template itself.

Some examples for the encapsulation of several different deletion stategies:

struct delete_std /* simple delete */
{
    public: template <class T> static inline void Delete(T*& Instance) {
delete Instance; Instance = NULL; };
};
struct delete_arr /* object arrays need delete[] for the invocation of their
destructors */
{
    public: template <class T> static inline void Delete(T*& Instance) {
delete[] Instance; Instance = NULL; };
};
struct delete_com /* microsoft COM objects need release method called
instead of beinig deleteEd */
{
    public: template <class T> static inline void Delete(T*& Instance) {
Instance->Release(); Instance = NULL; };
};

Let the smart pointer template take a second type argument (template <class
T,typename DeletionStrategy = destroy_std>).
>From inside the template the required mechansim is inlined with
DeletionStrategy::Delete(Instance).

I could imagine putting the save_delete mechanism used by the boost library
smart pointers directly in the structs mentioned
above to avoid unneccessary source code overhead.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk