Union redux

Brad Roberts via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 1 16:27:51 PDT 2015


On 6/1/15 2:40 PM, Steven Schveighoffer via Digitalmars-d wrote:
> On 6/1/15 5:36 PM, Andrei Alexandrescu wrote:
>> On 6/1/15 2:22 PM, Steven Schveighoffer wrote:
>>> I would make it clear here what you mean. I can't tell what "the rule"
>>> is (there may be 2 rules, or 1, but I can't tell), and whether Andrei
>>> agrees we should do it or not.
>>
>> Unions should accept all types, including those with @disabled or
>> elaborated constructors/postblits/dtors. Essentially a union is
>> appropriate storage for any type mentioned in its members, whilst
>> leaving it to its user to write and read the needed values. -- Andrei
>>
>
> So what happens on destruction? What about postblit? This was the piece I'm not understanding.
>
> For D, requiring that a struct can be constructed statically is a win here.
>
> -Steve

I think the basic thinking is that these two should be semantically identical:

struct(T) { T t; }

and

struct(T) { union { T } U; U t; }

Having extra members inside the union certainly make the topic a little more complex, certainly, but 
the above should be a good base to start from.


More information about the Digitalmars-d mailing list