Boost logo

Boost :

From: Rainer Deyke (root_at_[hidden])
Date: 2002-02-07 10:40:48


----- Original Message -----
From: "Howard Hinnant" <hinnant_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, February 06, 2002 5:42 PM
Subject: Re: [boost] move semantics

> template <class T>
> void
> swap(T& a, T& b)
> {
> T tmp(move(a)); // move construct
> a = move(b); // move assign
> b = move(tmp); // move assign
> }
>
> None of these was intended to be a relocation, though the last move
from
> tmp certainly could be since the next (implied) statement is the
> destruction of tmp.

The swap above is potentially less effecient than a relacating swap.
It also fails entirely on classes that can only support relocation but
not move:

class C {
public:
  C() : fp(fopen("myfile", "rb") { if (!fp) throw something; }
  ~() { fclose(fp); }
private:
  FILE *fp;
};

It is not always practical for classes to define a null state with no
resources allocated.

--
Rainer Deyke | root_at_[hidden] | http://rainerdeyke.com

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