Union redux

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 2 16:14:04 PDT 2015


On 06/03/2015 01:07 AM, Andrei Alexandrescu wrote:
> On 6/2/15 3:42 PM, Steven Schveighoffer wrote:
>> On 6/2/15 6:14 PM, Andrei Alexandrescu wrote:
>>> On 6/2/15 2:57 PM, Timon Gehr wrote:
>>>> OK. What about copying in instead of out?
>>>
>>> If the appropriate type has already been constructed, assignment
>>> suffices. Otherwise, emplace(&target, source) is needed. -- Andrei
>>
>> My concern is if you copy the enclosing type. This means you have
>> already copied the bits, and the postblit of the enclosing type is
>> responsible for calling the postblit of the valid union member (as
>> defined by the semantics of the type). How does it do that?
>
> Copying unions as a whole won't do any miracles. Just memcpy. -- Andrei
>

Copy is memcpy & postblit.

If the bit-copy has already been done (e.g. execution is inside a 
postblit) emplace(&f,f) seems wasteful.


More information about the Digitalmars-d mailing list