Access to intersection fields of an algebraic data type

Nicholas Wilson iamthewilsonator at hotmail.com
Sun Jan 20 00:38:42 UTC 2019


On Saturday, 19 January 2019 at 17:40:53 UTC, sighoya wrote:
> Is there a solution for the following problem:
>
> import std.variant : Algebraic;
>
> struct A
> {
>     int a=2;
> }
>
> struct B
> {
>     int a=2;
> };
>
> void main()
> {
>     Algebraic!(A,B) c=A();
>     writeln(c.a);
>     return;
> }
>
> Error: no property a for type VariantN!(4LU, A, B)

Try using http://code.dlang.org/packages/taggedalgebraic I find 
it much better.


More information about the Digitalmars-d mailing list