[Issue 12597] Payload getter for std.typecons.Typedef

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Apr 24 04:21:07 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12597

--- Comment #10 from bearophile_hugs at eml.cc ---
(In reply to Andrej Mitrovic from comment #9)

> we might as well make the `Typedef_payload` field public.

Yes, making that field public could be the simplest solution. But the field
needs to be renamed to a nicer/shorter name, perhaps like "_data".


> Otherwise we could make a UFCS function that
> would avoid symbol conflicts:
> 
> -----
> V getValue(T)(T t)
>     /* if (isTypedef!T) */
> {
>     return t.Typedef_payload;
> }
> -----
> 
> This would be usable via:
> 
> Typedef!Type x;
> x.getValue();  // assuming 'Type' doesn't define getValue
> getValue(x);   // workaround if 'Type' *does* define getValue
> 
> Let me know what you think.

Seems good, but to reduce the frequency of name clashes I'd like a less
generic/common name, like "typedefVal". And if possible it should return by
reference:

Typedef!Int x;
x.typedefVal++;

--


More information about the Digitalmars-d-bugs mailing list