Thread overview
Traits in a template enum
Oct 10, 2021
Some Guy
Oct 10, 2021
Some Guy
Oct 10, 2021
Adam D Ruppe
Oct 10, 2021
Some Guy
Oct 10, 2021
Mike Parker
October 10, 2021

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:

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.

October 10, 2021

It actually looks like I'm having problems wherever I try to pass that enum as a template parameter.

October 10, 2021
On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote:
> I have this enum to get the type

enums hold values, not types.

try alias instead
October 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:

>

I have this enum to get the type

enums hold values, not types.

try alias instead

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?

October 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.