Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-03-08 07:55:30


on 3/8/00 5:11 AM, Kevin Atkinson at kevinatk_at_[hidden] wrote:

>> template <typename T>
>> void ClonePtr<T>::Parms::assign(T * & rhs, const T * lhs) const {
>> if (typeid(*rhs) == typeid(*lhs)) {
>> rhs->assign(lhs);
>> } else {
>> delete rhs;
> add the line
> rhs = 0; // for exception safety incase clone throws
>
> I thought I saved it before I attached it......
>
>> rhs = lhs->clone();
>> }
>> }

You could do better. Wouldn't you rather assignment gave the strong
guarantee in this case?

temp = lhs->clone();
delete rhs;
rhs = temp;

[gee, the raw pointer member rhs is starting to look like it ought to be a
std::auto_ptr to me ;)]


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