Boost logo

Boost :

Subject: Re: [boost] move library / trait needed
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2009-04-30 16:15:40


David Abrahams wrote:
>
> are you familiar with
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2855.html
> ?

I've just skimmed part of the discussion, just to see what the problem
was and to think that noexcept is a great idea that can also help
performance and code size.

> Until the committee decides exactly how to handle it and compilers catch
> up with the feature they add, we need a workaround for that problem,
> both for C++03 and C++0x. The simplest approach requires a trait called
> has_nothrow_move<T> which can be used to SFINAE-out pair's move
> constructor unless its members all have a nonthrowing move constructor.
> It would be reasonable to say
>
> template <class T>
> struct has_nothrow_move : has_move_constructor {};

What does has_nothrow_move exactly mean? It means that type has a
nothrow T(T &&x) overload or that conversion from rvalue ref to a type
does not throw (including copy constructor if the type has not
overloaded the constructor with both const & and &&)? In the working
draft there are some "move" traits that are confusing to me regarding
this issue (MoveConstructible requires RvalueOf<T> && Constructible<T,
RvalueOf<T>::type> which I think is true for C++03 types).

I think has_move_constructor could be just "is_movable" (in the
emulation library "is_movable" means "this type has activated move
emulation", the T(rv<T> &) overload). For compilers with rvalue
references, I'm not a language expert so I need someone that could write
such a trait (can we easily detect if a type has the T(T&&t) constructor?).

For compilers with rvalue reference, if all types in the course are
going to use the portable syntax (that is, they are going to define
BOOST_HAS_MOVE_EMULATION macro) BOOST_HAS_MOVE_EMULATION can be used to
put a typedef that will mark those types as having a move constructor.

Do you also want me to tweak container/detail/pair.hpp implementation
and apply SFINAE for move constructors?

I can do some work tomorrow (the trait), and commit it to sandbox.

Best,

Ion


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