Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-11-30 10:35:33


"Peter Dimov" <pdimov_at_[hidden]> writes:

> From: "David Abrahams" <dave_at_[hidden]>
>>
>> Hi,
>>
>> I'm wondering whether the get_pointer function used by mem_fn et
>> al. is really justified. Since you can't invoke a member function on a
>> null pointer anyway, why not simply use &*p for this purpose?
>
> The original reason for using get_pointer in mem_fn is that mem_fn does not
> require get_pointer(p) to return &*p, or p.get(), or a raw pointer. It only
> expects an object with operator->* defined. Another reason is that supplying
> a get_pointer() for an existing type is (potentially) less intrusive than
> enabling the &*p syntax.
>
> On the other hand... the ((*p).*f)(...) form would work with most smart
> pointers and iterators, so it might be worth exploring.

Yes, and in particular it would work with std::auto_ptr, which I know
is not a candidate for bind because it's not CopyConstructible, but it
is important for other reasons.

Maybe the thing to do is to provide a generalized get_pointer template
which does &*p.

And now, on to a tougher problem:

What's the generic form to use for checking whether a Dereferenceable
type is NULL?

The only forms which work for std::auto_ptr is:

    !p.get()
    !p.operator->()

I'd use the second one for all class types, but STLPort's debug mode
asserts instead of returning 0. It's a nonconforming but IMHO very
reasonable extension :(.

-- 
                       David Abrahams
   dave_at_[hidden] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

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