Boost logo

Boost :

Subject: Re: [boost] Proposal: null pointer class
From: Martin Törnwall (herede_at_[hidden])
Date: 2009-06-15 16:36:08


Lucanus Simonson wrote:
> All that said, I'm not sure how much we need this in boost. In my own code I would just use a C-style case in such cases, or reinterpret_cast<char*>(0) if C-style casts were frowned upon by offical style policies. You can't call char*() because it is a syntax error but typedef char* charp; charp() is legal syntax. I template was just doodling with a way to call the pointer default constructor as directly as possible without generating syntax errors. (char*)0 is about the most succinct you can get, but regardless of what you do, you still have an error prone overload because it is up to the user to remember to cast null to the desired pointer type. Since the problem with pointer type overloads and null value is that it is error prone, and not that it is hard to do, I don't think trying to make it easier is solving the real problem. All you can do is avoid defining such overloads in the first place.
But a templated null pointer class also makes the code more clear, in my
opinion. When passing null pointers as arguments to functions we can
see, by merely looking at the call, what parameters the function expects
to receive, which might give an indication of what it actually does.


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