Boost logo

Boost :

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


auto_ptr isn't a great solution, I'd rather not have to new everything that
can be changed inside a function. How would you handle a class member
that's not a pointer?

Anyway, the classes I suggested make it explicitly clear what's going on,
out and in_out, with helper functions that you use at the point of
invocation to get an object of the desired type, so, at the invocation it's
explicit that param x is out, and param y is in_out. Plus you get to avoid
using pointers, which is always nice.

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

> "Justin M. Lewis" wrote:
> > And, again, I HAVE been using these classes. That's why I brought them
> > here. I had a problem with functions not being clear, I found a
solution,
> > that's enforceable, in that people using the libraries I write have to
> > adhere to it, I know other people like the idea after having discussions
> > with them, so I thought I'd see about giving it to boost and having it
out
> > there where it's easily accessible to a large number of people.
>
> This thread /has/ gone around in circles.
>
> IMHO, I like the idea of code clarity. OTOH, I think there are other
> solutions to the problem. Please allow me to elaborate the three types
> of parameters and conventions (some already existing).
>
> In parameters: use a const reference or std::auto_ptr<>. For example:
> void f( T const& t_ );
> T t;
> f( t );
>
> void f( std::auto_ptr< T > t_ );
> std::auto_ptr< T > t( new T() );
> f( t );
>
> Out parameters: use return values or std::auto_ptr<>. For example:
> T f();
> T t = f(); // may have problem with troublesome copy constructors
>
> std::auto_ptr< T > f();
> std::auto_ptr< T > t = f(); // no problem with troublesome copy
> constructors
>
> In/Out parameters: use pointers or smart pointers. For example:
> void f( T* t_ );
> T t;
> f( &t );
>
> void f( boost::dumb_ptr< T > t_ ); // a pointer type that doesn't
> transfer ownership
> std::auto_ptr< T > t( new T() );
> f( boost::dumb_ptr< T >( t.get() );
>
> I think looking solely at the client code, it should be obvious to any
> maintainer what's going on. Also, the only convention above that's not
> already in use is the one with dumb_ptr<>. What do you think?
>
> 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