|
Boost : |
From: Daryle Walker (darylew_at_[hidden])
Date: 2005-09-23 06:41:28
On 9/21/05 9:38 PM, "David Abrahams" <dave_at_[hidden]> wrote:
> Ariel Badichi <abadichi_at_[hidden]> writes:
>
>> David Abrahams wrote:
>>>>> it's easy to arrange that only a literal zero works there.
>>>>
>>>> How?
>>>
>>> Allow assignment only from a private member pointer type. It's
>>> similar to the operator safe_bool idiom.
>>
>> I thought you might mean that. That allows more than a literal zero,
>> though (e.g., 5 * 5 - 25).
>
> Yikes! I didn't know that. Too bad!
Maybe it's not as "too bad" as you two think. You can use more than a
literal zero for the conventional null-pointer too! Any integral expression
that can be resolved at compile time that evaluates to zero can be used:
void * x = 20 - 22 + 2; // works as NULL pointer!
See section 4.10, paragraph 1 of the standard. (Also see s4.11-p1 and
s5.19-p1.) So allowing this case is not any more surprising than the rules
for built-in pointers.
>> By the way, that might work well for smart
>> pointers; why don't shared_ptr and friends use this idiom?
>
> Maybe because it allows more than a literal zero?
If that's the reason, maybe it could be re-evaluated.
-- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk