Boost logo

Boost :

Subject: Re: [boost] Proposal: null pointer class
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2009-06-15 15:21:05


Martin Törnwall wrote:
> Hello Boost developers,
>
> I'd like to propose the inclusion of a null_ptr class in Boost.
> template<typename T> class null_ptr
> {
> public:
> operator T*() const
> {
> return reinterpret_cast<T *>(0);
> }
> };
>

Why not make it even simpler and more general.

template <typename T>
T null() {return T(); }

int main()
{
   func(NULL);
   func(null<char*>());
}

It also gives the null string or null value of any other type that default initializes to its null value. I'm pretty sure the default initialized pointer value is null according to the standard, so this should be portable, but I am not an expert on the standard.

Regards,
Luke


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