Boost logo

Boost :

Subject: Re: [boost] C++03 unique_ptr emulation
From: David Abrahams (dave_at_[hidden])
Date: 2009-01-09 13:45:57


on Fri Jan 09 2009, Anthony Williams <anthony.ajw-AT-gmail.com> wrote:

> boost::move should return T.
>
> Sorry for jumping in here, but I'm not sure that it should. Consider
>
> movable m;
> boost::move(m);
>
> In C++0x, move(m) is equivalent to static_cast<movable&&>(m), which
> just obtains a reference. If boost::move<T> returns a T then the code
> above will create a temporary which moves the data out of m, and then
> destroy that temporary, leaving m a hollow shell.

So you're saying, in other words, that "move(x)" really means "you have
permission to move x" but the one I proposed would mean "move it, now."

OK, good point.

So what about this horrible little proposal?

  template <class T>
  struct rv<T> : T
  {
   private:
      rv();
      ~rv();
      rv(rv const&);
      void operator=(rv const&);
  };

  template <class T>
  boost::enable_if<is_class<T>, rv<T>&>
  move(T& x)
  {
    return static_cast<rv<T>& >(x);
  }

Does that solve any problems?

Yeah, I know it's not theoretically portable, but it should be portable
in practice. Especially when it comes to emulating language features, I
care less and less about the letter of the law :-)

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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