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

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

p.set(new X);

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

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