opDispatch

Tobias Pankrath via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 25 08:29:13 PST 2014


On Thursday, 25 December 2014 at 16:24:10 UTC, Danny wrote:
> Adam: Thanks, that was very illuminating! I tried and these 
> work indeed.
>
> Is there a function like opDispatch which can be used (at 
> compile time) to refer to something by name wh ether or not 
> it's custom? (to access something like "value.a" safely. mixin 
> and string concatenation looks like would have problems with 
> special characters easily)
>
> (Something like getattr(x, "a") in Python)

http://dlang.org/traits

__traits(getMember, x, "a").

Not sure how that works together with opDispatch. I am not sure
why you see safety reasons at compile time though. If there is no
such attribute, you'll just get an error.


More information about the Digitalmars-d-learn mailing list