From: Sohail Somani (s.somani_at_[hidden])
Date: 2007-04-16 16:40:25


> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Ion Gaztañaga
> Sent: Monday, April 16, 2007 10:33 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] [shared_ptr] dangerous implementation of
> moveconstructor
>
> std::vector<T> myvect(...);
> //myvect's destructor is called, the object is not longer usable
> std::vector<T> myvect2(std::destructive_move(myvect));
> myvect.resize(1000); <-- COMPILATION ERROR

That pretty much goes against normal C++ scoping rules (theyre not related here but from a readability pov, they are) and would be very confusing.

In this code here:

if(some_runtime_condition)
{
  ...std::destructive_move(myvect)...
}
...
if(!some_runtime_condition && some_other_runtime_condition)
{
   use_myvect(myvect);
}

It isn't easy for the compiler to help you. Well defined and standard-mandated semantics are better in the long run, even if its possible for the case you had above not be an error (should be a warning though!).

The rule should be simple:

After moving, the moved object (i.e., the argument to std::move) should be destructible.

I don't think being assignable makes sense because that implies that a default constructor is sensible for T. I can imagine this is more intuitive C++ and is easier for compilers to implement.

Thanks for listening (and discussing this very important topic!)

Sohail