Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2008-06-24 11:53:02


On Jun 24, 2008, at 7:07 AM, Daniel James wrote:

>> From the move semantics thread:
>
> 2008/6/24 David Abrahams <dave_at_[hidden]>:
>> Daniel James wrote:
>>> It mostly works. I've found two problems so far. Firstly,
>>> is_convertible didn't work for the type,
>>
>> You found a bug in is_convertible?
>
> I don't know if it's a bug. The example below fails to compile.
>
> #include <boost/type_traits/is_convertible.hpp>
>
> template <typename T> struct move_from {};
> class Y
> {
> Y(Y& rhs);
> public:
> Y(move_from<Y>) {}
> };
>
> bool const r = boost::is_convertible<move_from<Y>, Y>::value;

The tr1::is_convertible, which was born from boost::is_convertible,
considers its "from" to be an lvalue when detecting convertibility.
The C++0X std::is_convertible considers its "from" to be an rvalue
when detecting convertibility. If one wants to restrict
is_convertible to only consider lvalue froms, one simply specifies an
lvalue reference: is_convertible<F&, T>::value (from is now
considered as an lvalue).

There is motivation for this change here:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2255.html

(search for "is_convertible").

-Howard


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