|
Boost : |
Subject: Re: [boost] [variant] Basic rvalue and C++11 features support
From: Paul Smith (pl.smith.mail_at_[hidden])
Date: 2013-01-08 12:44:01
On Tue, Jan 8, 2013 at 7:28 PM, Nevin Liber <nevin_at_[hidden]> wrote:
> On 8 January 2013 08:18, Hartmut Kaiser <hartmut.kaiser_at_[hidden]> wrote:
>
>> The only thing the standard requires wrt a moved-from object is that they
>> are left in a valid (although unspecified) state. Thus simply nulling out
>> the pointer in the reference_wrapper should do the trick (just as Joel
>> proposed).
>>
>> See for instance: 17.6.5.15 - [lib.types.movedfrom]
>>
>> <quote>
>> Objects of types defined in the C++ standard library may be moved from
>> (12.8). Move operations may
>> be explicitly specified or implicitly generated. Unless otherwise
>> specified,
>> such moved-from objects shall be
>> placed in a valid but unspecified state.
>> </quote>
>
>
> If I remember correctly, that section was added at the 11th hour so to
> speak (at the Madrid meeting, days before ratifying the standard) so we
> didn't have to go through the entire library figuring out and documenting
> which operations were and were not legal to call on moved-from standard
> library objects.
>
> Other than destroyable and (possibly) assignable, it really is up to the
> author of the class to define what operations are allowed on moved-from
> objects. In other words, authors are allowed to make "not in the
> moved-from state" as a precondition for operations they don't want to allow
> in that state.
>
> A nulled-out pointer in the reference wrapper meets this requirement.
> --
> Nevin ":-)" Liber <mailto:nevin_at_[hidden]> (847) 691-1404
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost.Variant defines operator< for variants, so they are easily
usable as keys for associative containers. Table 20 says that
moved-from objects "must still meet the requirements of the library
component that is using it. The operations listed in those
requirements must work as specified whether the object has been moved
from or not." Obviously, it's required that keys be comparable. But
trying to compare two recursive variants that hold the same
recusrive_wrapper type is UB if one them is null. Hence, recursive
variants are no longer valid key types for associative containers
(technically).
-- Paul Smith
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk