|
Boost : |
Subject: Re: [boost] Proposal: null pointer class
From: Martin Törnwall (herede_at_[hidden])
Date: 2009-06-15 15:49:10
Stewart Robert wrote:
> reinterpret_cast isn't needed here. Just return 0.
Thank you for pointing that out. I threw it in in case some obscure compiler would complain with a warning.
Lucanus Simonson wrote:
> 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.
You make a good point, but the purpose of the class I proposed is very specific -- that of solving problems related to the use of the NULL pointer constant. I believe that it could be somewhat confusing to have a "null" template function that returns both null pointers and objects initialized with the default constructor.
Regards,
Martin Törnwall
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk