Boost logo

Boost :

From: Kevin Atkinson (kevinatk_at_[hidden])
Date: 2000-03-07 07:01:36


On Tue, 7 Mar 2000, Kevlin Henney wrote:

> In message <Pine.LNX.4.10.10003061513200.6848-100000_at_kevins-linux>,

> >Here is a more complicated but more efficient operator=:
> >
> > template <typename T>
> > CopyPtr<T> & CopyPtr<T>::operator= (const CopyPtr<T> & other)
> > {
> > if (other.ptr == 0) {
> > delete ptr;
> > ptr = 0;
> > } else if (ptr == 0) {
> > ptr = new T(*other.ptr);
> > } else {
> > *ptr = *other.ptr;
> > }
> > return *this;
> > }
>
> And here is one that is simpler, exception safe, but only as efficient
> as the original version:
>
> template<typename T>
> CopyPtr<T> & CopyPtr<T>::operator=(const CopyPtr & other)
> {
> T * old = ptr;
> ptr = other.ptr ? new T(*other.ptr) : 0;
> delete old;
> return *this;
> }

How is mine not exception safe?

---
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