Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2002-02-05 19:34:33


On Tuesday, February 5, 2002, at 04:28 PM, Hamish Mackenzie wrote:

> No you are not misreading. And it was not intended to be "pseodo"
> code.

Oh, sorry. I wasn't familiar with gcc's std::construct.

> Although I don't have a copy of the standard and the sgi
> documentation does not seem to include the version of std:::construct
> that takes one argument (though it is in gcc 3).

It isn't in the standard. About the closest thing is allocator has a
member called construct:

template <class T>
class allocator
{
public:
        void construct(pointer p, const T& val);
};

No matter, this is just syntax sugar for placement new.

Concerns:

1.

> The default move( T &, T & ) would be implemented using swap (which in
> most cases is no throw). For scalar types it would use assignment.

Implementing move with swap is needlessly inefficient. Ok, we can
specialize it for scalars to not be inefficient. What about user
defined PODS? Maybe with is_POD we could further specialize it. But
even for something like std::string it is slower than need be. Sure, it
is a lot faster than assignment. But it is twice as slow as it needs to
be.

I think any object with a non-trivial move should be expected to provide
move semantics if it expects to move. A trivial move is one that works
as a non-throwing copy. We do this already with copy. If you want to
copy, and the compiler generated copy doesn't work right, you've got to
roll up your sleeves and provide it. Relying on swap for move is
backwards (due only to history). If a class provides proper move
semantics, then it need not also specializing swap as swap can be
programmed to detect and use move at no efficiency loss.

2. How does one detect if an object implements move semantics (in
templated code)?

3. How does one move from a temporary?

-Howard


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