Union redux

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 1 19:18:33 PDT 2015


On Tuesday, 2 June 2015 at 00:11:09 UTC, Andrei Alexandrescu 
wrote:
> On 6/1/15 3:43 PM, deadalnix wrote:
>> On Monday, 1 June 2015 at 19:43:33 UTC, Andrei Alexandrescu 
>> wrote:
>>> Do not define constructors. They ostensibly imply commitment 
>>> to
>>> remembering to call the appropriate destructor. A union can 
>>> only be
>>> default constructed (with its init value as described) and 
>>> has no
>>> destructor.
>>>
>>
>> This is implied in C++ because of manual memory management. I 
>> don't
>> think it is in D.
>
> It is because destructors exist in both languages.
>

It is common in D to have a struct with a constructor and no 
destructor.

>>>> 5/ union currently disallow members with postblit and/or 
>>>> destructor . It
>>>> seems that this was needed in C++ as per Andrei's comments. 
>>>> It seems to
>>>> me that, because of manual memory management, C++ would have 
>>>> a lot more
>>>> struct with copy constructor and/or destructor than in D, so 
>>>> I'm not
>>>> sure if this require change in spec. Andrei, can you give 
>>>> more details
>>>> on the C++ situation here ?
>>>
>>> That rule has hurt C++ everywhere, and the community credits 
>>> Lois
>>> Goldthwaite for pushing the current rule, which allows types 
>>> with
>>> cdtors in unions. Let's go the same way, unions are all but 
>>> useless
>>> otherwise.
>>>
>>
>> Without knowing the rationale in C++, it is difficult to 
>> assert that
>> this is also valid in D. You seems to be knowledgeable of the 
>> subject,
>> so surely you can enlight us on that one.
>
> I intentionally gave enough information to allow easy further 
> research. http://goo.gl/19Nol5 lists N2412 and N2248 as top 
> hits, their motivation sections are relevant.
>

The abstract of the 2 above mentioned link only discuss the 
*constructor* case. It was never question of struct with 
constructor not being able to be in union.

You attitude is only weakening your point.


More information about the Digitalmars-d mailing list