How get struct value by member name string ?

bauss jacobbauss at gmail.com
Fri Jun 2 19:16:04 UTC 2023


On Tuesday, 30 May 2023 at 15:43:12 UTC, Steven Schveighoffer 
wrote:
> On 5/30/23 4:46 AM, John Xu wrote:
>> How to put above enum as a function parameter? Following code 
>> wouldn't work:
>> 
>>      string getTMember(T t, enum string memberName) {
>>          return __traits(getMember, t, memberName);
>>      }
>
> compile time parameters come before runtime parameters:
>
> ```d
> string getTMember(string memberName)(T t) {
>    return __traits(getMember, t, memberName);
> }
>
> // used like
> auto v = getTMember!"name"(t);
> ```
>
> -Steve

Yeah I did fix it in my message right after


More information about the Digitalmars-d-learn mailing list