Boost logo

Boost :

From: Ralf W. Grosse-Kunstleve (rwgk_at_[hidden])
Date: 2006-03-08 18:05:12

Does this patch for boost/scoped_array.hpp look useful?

< T * release() // never throws
< {
< T * result = ptr;
< ptr = 0;
< return result;
< }

It allows me to use boost::scoped_array almost like an auto_ptr:

    boost::scoped_array<int> result(new int[size]);
    // do something to result
    // if an exception is thrown result will be cleaned up
    return result.release();

    boost::scoped_array<int> foo_result(foo(1000));
    // code is still exception safe

I wouldn't need this if

  - we had std::auto_array (don't think it exists)
  - std::vector<int>(size) wouldn't do the default construction of all elements
and I didn't care about having two pointers instead of just one (sometimes I
actually do care)
  - boost::scoped_array::ptr was protected instead of private so that I could
inherit and add release()

Are there arguments for not adding release()?


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

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