Boost logo

Boost :

From: Justin M. Lewis (boost_at_[hidden])
Date: 2003-05-04 17:34:14

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

> "Justin M. Lewis" wrote:
> > > Can we agree, then, that there's no need for c_out?
> > >
> >
> > Of course not, because you haven't yet addressed the issue of
> > objects, OR polymorphic types, OR large structs that can't be copyed
into a
> > retrun value, OR a function where you have a lot of return types.
> Yes, we have. One more time:
> T f(); // if T has a cheap copy
> T const& f(); // if f owns the return value, can handle polymorphic
> types
> dumb_ref< T > f(); // if T doesn't have a cheap copy, f has to own the
> return value, can handle polymorphic types
> dumb_ptr< T > f(); // if the return value can be NULL, f has to own
> the return value, can handle polymorphic types
> result< T > f(); // if the return value is gotten from an asynchronous
> call
> tuple< T, U > f(); // if f has many return values, I think one can use
> bind, too

You're not passing the param in, so f either owns, or is allocating the
object in every one of those cases, and that's not the case for every out
param. An out param simply means that the function its being passed to does
NOT care about the contents of the object, it is going to modify it in such
a way that the current state of the object does not matter. So, then the
problem with your method becomes you have to new and delete all of those out
params you're using, except in the case where f is a member function of an
object where the out param is a member of the object, not always, the case,
in fact, I'd say that's the uncommon case, where you return internal data
from an object and give a handle to someone else to modify it.

> Did I miss anything? BTW, one can probably combine some of the above to
> get the exact flavor of return one wants.
> Noel
> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at