|
Boost : |
From: Kevin Atkinson (kevinatk_at_[hidden])
Date: 2000-03-08 08:21:21
On Wed, 8 Mar 2000, Dave Abrahams wrote:
> 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;
I guess. It depends on how you look at it.
>
> [gee, the raw pointer member rhs is starting to look like it ought to be a
> std::auto_ptr to me ;)]
>
I don't know how serious you are but by pointers are different than
auto_ptr when ever one of my pointers is assigned to another a copy is
made. Auto_ptr on the other hand transfers ownership.
--- Kevin Atkinson kevinatk_at_[hidden] http://metalab.unc.edu/kevina/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk