Boost logo

Boost :

From: Justin M. Lewis (boost_at_[hidden])
Date: 2003-05-03 18:56:36


----- Original Message -----
From: "Noel Yap" <Noel.Yap_at_[hidden]>
To: "Boost mailing list" <boost_at_[hidden]>
Sent: Saturday, May 03, 2003 4:48 PM
Subject: Re: [boost] Re: in/out parameters, codingstylesandmaintenance

> "Justin M. Lewis" wrote:
> >
> > ----- Original Message -----
> > From: "Noel Yap" <Noel.Yap_at_[hidden]>
> > To: "Boost mailing list" <boost_at_[hidden]>
> > Sent: Saturday, May 03, 2003 4:13 PM
> > Subject: Re: [boost] Re: in/out parameters, codingstylesandmaintenance
> >
> > > Noel Yap wrote:
> > > > std::auto_ptr< T > t( new T() );
> > > > f( boost::dumb_ptr< T >( t.get() ); // clearly an in/out parameter
> > >
> > > Or if you don't want to dynamically allocate t:
> > >
> > > T t;
> > > f( boost::dumb_ptr< T >( &t ) ); // clearly an in/out parameter
> > >
> > > static T t;
> > > f( boost::dumb_ptr< T >( &t ) ); // clearly an in/out parameter
> > >
> > > boost::dumb_ptr< T > t = f(); // must be an out parameter whose
memory
> > > is managed by f()
> > >
> > > T t = *f().get(); // must be an out parameter whose memory is
managed
> > > by f()
> > >
> > > T &t = *f(); // must be an out parameter whose memory is managed by
> > > f()
> > >
> >
> > I'm going to have to disagree with those being clearly in_out params.
What
> > if the function just takes a pointer?
>
> If you wrote the function, why did you write it taking in a pointer if
> the intent is not an in/out parameter?

Maybe you're in a place where you just had to work with pointers. It
happens.

>
> >While we do tend to avoid using
> > pointers these days, it's not possible to avoid them entirely, and there
is
> > a lot of code where pointers are being passed around.
>
> In this situation, how is c_out and c_in_out going to help where
> boost::dumb_ptr<> will not?
>
> > So, how do you
> > differentiate the case where it's just a pointer being passed, and it's
an
> > in_out param?
>
> I think you're saying, "I don't want to write functions taking in
> pointers even for in/out parameters since there's such a large code base
> taking in pointers for in parameters." If so, for new functions what
> about using:
>
> void f( boost::dumb_ptr< T > t ); // this is an in/out parameter
>
> > And, there's still the issue of, we LIKE to avoid using
> > pointers whenever possible, which you're not doing, you're requiring the
use
> > of pointers in a case where they're easily avoidable.
>
> Can you explain or elaborate what you mean by "using pointers", please?
>

using pointers, it seems pretty self explanatory to me.
myfunc(const obj *ptr);

If you're not dealing with something where you know you have allocated data
floating around, you should use a reference.

myfunc(const obj &ptr);

But, like I said, there are cases where you have to allocate data. So, how
do you differentiate calls like

myfunc1(const obj *ptr)

from

myfunc2(obj *ptr) ?

I mean, if you just put dumb_ptr in place of both, how is it any different?
How can you tell one from the other, without looking up the prototype?

I'm just saying, passing by pointer doesn't explicitly tell you anything,
whereas, c_out and c_in_out do.

> Thanks,
> Noel
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


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