Proposal: Still using NULL ?

Hello ! Scott Meyers has presented a replacement for the (evil) NULL macro, in his "More Effective C++". I have posted some variation of it in the Boost File Vault, under the name 'boost_null.zip', and, I was wondering if it could fit in boost/utility.hpp. This is of no major innovation, and won't save the world, but at least we can say goodbye to NULL ! Indulge yourslef the NULL you desreve ! -- Anis Benyelloul

Anis Benyelloul wrote:
Hello !
Scott Meyers has presented a replacement for the (evil) NULL macro, in his "More Effective C++".
The macro isn't evil. It's just useless.
I have posted some variation of it in the Boost File Vault, under the name 'boost_null.zip', and, I was wondering if it could fit in boost/utility.hpp.
Did you read the NULL-related discussion in the "singleton design plan" thread? ( http://thread.gmane.org/gmane.comp.lib.boost.devel/128618 ) Regards, m Send instant messages to your online friends http://au.messenger.yahoo.com

The macro isn't evil. It's just useless. Like I said it won't save the world from space invaders, but I find it improves readability (somewhat) ... And it solves a longstanding problem of "#define NULL (void*)0 doesn't suit C++, use 0 instead,... etc ... etc ..."
Did you read the NULL-related discussion in the "singleton design plan" thread? ( http://thread.gmane.org/gmane.comp.lib.boost.devel/128618 )
I just had a quick look ! I seems that their concern was about redefining NULL itself, not about a NULL replacement as such. By the way, I didn't redefine NULL. Yours, -- Anis Benyelloul

Anis Benyelloul wrote:
I just had a quick look! I seems that their concern was about redefining NULL itself, not about a NULL replacement as such. By the way, I didn't redefine NULL.
The problem was indeed mostly about me redefining NULL (which I admit now was a bad idea), but there is still a problem with the template based null that was shown to me by Eric Niebler (edited to make it look more like a real world example): template < typename Type > struct SmartPtr { SmartPtr ( Type * ) { } }; void Bar ( SmartPtr < int > ) { } void Test ( ) { Bar ( boost::null ); // fails, requires two user defined conversions } I suppose SmartPtr could add a constructor taking boost::null_type, but that seems horribly redundant, especially when passing 0 for null would still work perfectly without the need for another constructor. Any ideas for solving this use case? -Jason
participants (3)
-
Anis Benyelloul
-
Jason Hise
-
Martin Wille