Boost logo

Boost :

Subject: Re: [boost] [variant] Please vote for behavior
From: Dave Abrahams (dave_at_[hidden])
Date: 2013-01-25 18:58:55

on Fri Jan 25 2013, Neil Groves <> wrote:

>> I think variant after move is like int without initialization:
>> int i;
>> cout << i; // don't do this
>> If the fact, that moved-from objects are only good for destruction or
>> assignment-to is accepted, then invariants for moved-from objects are
>> allowed to be violated.
> I completely agree with the notion that a moved-from object simply should
> not be used in any manner.

Well, that's just wrong, for the non-destructive move model used by the
standard. The standard library relies on the ability to both assign
and destroy moved-from elements. If you want destructive move, that's a
whole research project. We on the committee who created rvalue
references couldn't figure out how to make it work.

> It is interestingly divergent from the typical Design by Contract
> idiom. It is much more usual, in my experience for the
> class-invariants to hold up to and including entry to the destructor.

I don't understand what any of that means.

> It seems that this divergence is of little importance to users of the
> language since we are not explicitly interested in calling the
> destructor.

Indeed we are! Trying to keep track of which elements have been
moved-from so you can avoid calling the destructor gets very hairy, very
quickly. Again, we couldn't figure out how to do it.

> If I understand correctly the standard is divergent

divergent from what?

> to allow sensible compiler implementations of clean-up code for
> moved-from objects.

I don't understand what you're saying here, either.

Dave Abrahams
BoostPro Computing                  Software Development        Training             Clang/LLVM/EDG Compilers  C++  Boost

Boost list run by bdawes at, gregod at, cpdaniel at, john at