From: Noel Yap (Noel.Yap_at_[hidden])
Date: 2003-05-03 20:18:08
Floris van den Berg wrote:
> Seeing a reference as a special pointer is imo fundamentally wrong.
I think it's fundamentally correct. Can you show me where thinking of a
reference as an implicitly dereferenced pointer doesn't work?
> reference is an alias for a variable, whereas a pointer is a memory address.
Doesn't the variable have a memory address? What about temporaries?
> Therefore you never need to check a reference for existence,
This is true.
> or deallocate
> memory while for a pointer you must.
This isn't true:
T* p = &t;
static T t;
T* p = &t;
std::auto_ptr< T > p( new T() ); // I'm not sure if you consider this
as me deallocating the memory
> Using a auto_ptr, a wrapper for
> pointers, on references is therefore plain wrong.
If I ever implied such a thing, I apologize.
> As for in, in_out and out
> parameters: you use it to make it apparent in your sourcecode and at
> compile-time which function parameters are changed and which not.
It's the same with the various uses of std::auto_ptr<> and the proposed
boost::dumb_ptr<>. The only difference being that the smart pointers
may contain NULL's whereas the proposed parameter wrappers cannot.
OTOH, what if NULL parameters are wanted?
> You need 3
> different templates for this.
I think I've shown how this can be done with one template class:
void f( boost::dumb_ptr< T const > in_ );
void f( boost::dumb_ptr< T > inOut_ );
boost::dumb_ptr< T > f(); // out parameter; can wrap dynamic, static,
or automatic memory
> If you propagate everything back to one
> dumb_ptr or auto_ptr or whatever you want to call it, you essentially ruin
> the beauty of the whole system.
Beauty is in the eye of the beholder ;-)
Using boost::dumb_ptr<> as suggested above accomplishes the original
intent of the proposed wrappers: differentiate, at the call site,
whether parameters are in, out, or in/out. Moreover, it does so with
one template class rather than three. Using Occam's Razor as a guide to
parsimony, if not for beauty, one is better than three.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk