copy-ctor's

Manu turkeyman at gmail.com
Mon May 27 04:52:14 UTC 2019


On Sun, May 26, 2019 at 7:55 PM Ola Fosheim Grøstad via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Monday, 27 May 2019 at 00:41:22 UTC, Manu wrote:
> > Well I'm obviously implementing a tagged union.
> > The language just needs to make the feature available, and let
> > me wrap it up.
>
> IIRC Bearophile suggested that the struct could provide a
> function or some mechanism that would tell the runtime what type
> the union contained. But Andrei didn't like it.

Right, that's a terrible idea. Who's to say that's how the union is used.

> Some sort of "type-switch" statement in the union with a
> conditional that is allowed to reference fields in the
> surrounding struct would be a possibility.

Sounds like a lib to me.

> The real problem isn't that one cannot come up with a decent
> solution, but that the semantics of C has been subsumed, and
> extended.

I don't really think there's a problem here, just @disable the default
copy/postblit/destructor in the presence of a union, and also make any
access to a member of a union un- at safe. The rest will fall out
naturally.



More information about the Digitalmars-d mailing list