digitalmars.D.learn - Traits in a template enum
- Some Guy (11/11) Oct 10 2021 I have this enum to get the type of a member field in a struct:
- Some Guy (2/2) Oct 10 2021 It actually looks like I'm having problems wherever I try to pass
- Adam D Ruppe (3/4) Oct 10 2021 enums hold values, not types.
- Some Guy (5/9) Oct 10 2021 Thanks! `alias typeOfMember(T, string member) =
- Mike Parker (3/5) Oct 10 2021 Types can be template arguments, if that's what you mean, but
I have this enum to get the type of a member field in a struct: `enum typeOfMember(T, string member) = typeof(__traits(getMember, T, member));` I'm having problems when I try to used it though. For example: ```D writeln(typeOfMember!(T, member).stringof); // Doesn't work: Error: initializer must be an expression, not `int[]` writeln(typeof(__traits(getMember, T, member)).stringof); // Expand the enum, it works. ``` What is the problem here? I'm using the LDC 1.27.1.
Oct 10 2021
It actually looks like I'm having problems wherever I try to pass that enum as a template parameter.
Oct 10 2021
On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote:I have this enum to get the typeenums hold values, not types. try alias instead
Oct 10 2021
On Sunday, 10 October 2021 at 12:48:49 UTC, Adam D Ruppe wrote:On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote:Thanks! `alias typeOfMember(T, string member) = typeof(__traits(getMember, T, member));` works. But I did not understand what you meant by "enums hold values, not types". Aren't types values at compile time?I have this enum to get the typeenums hold values, not types. try alias instead
Oct 10 2021
On Sunday, 10 October 2021 at 12:56:30 UTC, Some Guy wrote:But I did not understand what you meant by "enums hold values, not types". Aren't types values at compile time?Types can be template arguments, if that's what you mean, but they aren't values.
Oct 10 2021