Meta-programming detecting anonymous unions inside structs.
rikki cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Oct 21 00:56:27 PDT 2016
On 21/10/2016 8:55 PM, TheFlyingFiddle wrote:
> I am trying to port a serialization library I wrote in Lua some time
> ago. I've ran into a problem relating to types with anonymous unions
> inside.
>
> Given this code:
> enum Kind
> {
> none = 0,
> array,
> integer,
> floating,
> }
>
> struct Foo
> {
> Kind type;
> union
> {
> ulong integer;
> double floating;
> void[] array;
> }
> int nonUnionField;
> //...
> }
>
> How can I tell that "integer", "floating" and "array" are part the union
> while "nonUnionField" is not?
>
> Thanks in advance.
You're gonna have to use UDA's for that.
More information about the Digitalmars-d-learn
mailing list