Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-11-17 08:20:16


From: "Dan Gohman" <dgohman_at_[hidden]>
[...]
> Documentation:
>
> set
>
> void set(T * p); // never throws
>
> Stores a copy of p, which must have been allocated via a C++ new
> expression or be 0. Behavior is undefined if the stored pointer
> is not 0.

Rejected, sorry. :-) Introducing undefined behavior for its own sake is
never a good design. You can always use

BOOST_ASSERT(!p);
p.reset(new X);

in client code to emulate the behavior of your proposed 'set'.

In general, it is recommended practice to always assert() preconditions in
client code, instead of relying on in-library asserts. First, the library is
not required to have asserts, and second, the earlier you catch precondition
violations, the better (call stacks aren't universally available). So "by
the book" you'd have written

BOOST_ASSERT(!p);
p.set(new X);

that's not really that different from the above to warrant an interface
change.


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