Boost logo

Boost :

From: Angel Tsankov (fn42551_at_[hidden])
Date: 2008-07-21 05:52:28


Hello,

Is there any interest in a class template which acts like a pointer and
guarantees at compile time and at no CPU or memory cost (except when a
call to any of its methods is not inlined) that the pointer is not null?

One of the applications that I have found for this template is in
defensive programming to eliminate the chances that dereferencing a
pointer will result in undefined behaviour (when the pointer is null).
Using this template is superior to any alternative method (that I know)
to achieve the same result, since:
(*) it consumes no CPU (in contrast to null checks);
(*) the class template instances are copy constructible and copy
    assignable (in contrast to references which can also be used to
    guarantee unnullability);
(*) it is natively supported by the language and provides a 'real'
    guarantee (in contrast to 'design by contract');
(*) supports the natural syntax for access to the wrapped resource (in
    constrast to boost::ref).

Regards,
Angel Tsankov


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