Member Access Based On A Runtime String
Andrea Fontana via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 1 00:34:53 PST 2016
On Tuesday, 1 March 2016 at 05:05:40 UTC, Jack Stouffer wrote:
> In Python, I can do this:
>
> my_obj = Obj()
> string_from_func = func()
> setattr(my_obj, string_from_func, 100)
>
> Say func() returns "member1" or "member2", the setattr would
> then set either one of those to 100.
>
> Is there any equivalent in D?
Maybe if string_from_func can be computed at compile time.
Something like this:
http://dpaste.dzfl.pl/8bc21da1147a
?
More information about the Digitalmars-d-learn
mailing list