Boost logo

Boost :

Subject: [boost] boost/checked_delete.hpp
From: mbiddeg_at_[hidden]
Date: 2009-06-08 09:16:38


Hi Guys.
I need serious help here, though this is child's play for you all.
>From boost/checked_delete.hpp (attached),

template<class T> inline void checked_delete(T * x)
{
    // intentionally complex - simplification causes regressions
    typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
    (void) sizeof(type_must_be_complete);
    delete x;
}

template<class T> inline void checked_array_delete(T * x)
{
    typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
    (void) sizeof(type_must_be_complete);
    delete [] x;
}

* What's the result of applying sizeof to an incomplete type?

* Why is sizeof called twice?

* Why is the result of sizeof cast to void? What exactly does that line do?

* Is it an empty statement if the sizeof is legal?

* Why not apply x = 0; at the end?

This code is not too clear to me & the boost documentation is not either. Please assist. Please do not direct me to the C++ standard text.
Then again, smart pointers are simple to understand & use, but their implementations are all rather difficult to understand (maybe except scoped_ptr). Which brings me to one more question, why wasn't Andrei's technique of Smart_Ptr (Loki) chosen over the boost implementation technique (a class per smart pointer) for C++ 0x? His allows for an innumerable number of extension through policies. I ask this purely to understand why, not as a rejoinder.
Awaiting your feedback.
Thank you.
Nice day.

______________________________________________________________________

Kizza George Mbidde
Interconnect Billing Systems Analyst
IT
cell: +256 77 221 2982
email: mbiddeg_at_[hidden]
[cid:image001.gif_at_01C9E853.125FFD20]





image001.gif

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