Boost logo

Boost :

From: Noel Yap (Noel.Yap_at_[hidden])
Date: 2003-05-03 17:57:10

"Justin M. Lewis" wrote:
> auto_ptr isn't a great solution, I'd rather not have to new everything that
> can be changed inside a function.

If it's to be changed within the function, it's either an out parameter:

  T f();
  std::auto_ptr< T > f();
  boost::dumb_ptr< T > f();

or an in/out parameter:

  void f( T* t );
  void f( boost::dumb_ptr< T > t_ );

> How would you handle a class member
> that's not a pointer?

I don't understand. Why not take the it's address?

> 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.

Since dumb_ptr is just a wrapper around pointers, you can still avoid
using pointers, unless you consider references not to be pointers.

Also, what stops people from:

  T t = out( t_ );
  f( t ); // this is an out parameter

  T t = in_out( t_ );
  f( t ); // this is an in/out parameter


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