This is probably trivial or impossible Code Introspection...

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 19 22:32:00 PDT 2015


On 09/19/2015 10:21 PM, WhatMeWorry wrote:
> On Saturday, 19 September 2015 at 19:54:45 UTC, Adam D. Ruppe wrote:
>> On Saturday, 19 September 2015 at 19:52:56 UTC, WhatMeWorry wrote:
>>> So I've got type and value of each member, but I want their actual
>>> names?
>>
>> http://dlang.org/phobos/std_traits.html#FieldNameTuple
>>
>> You can also do something like `foo.tupleof[idx]["foo.".length .. $]`
>> for an individual thing but the phobos one should be the nicest.
>
>
> Thanks.  But now I have an even more fundamental problem.  I keep
> getting a FieldNameTuple is not defined.  But I've clearly got the
> import statement.  I even copied the example from Phobos verbatim:
>
> import std.traits;
>
> struct S { int x; float y; }
> static assert(FieldNameTuple!S == TypeTuple!("x", "y"));
>
> But I still get the error.
>
> Error: template instance FieldNameTuple!S template 'FieldNameTuple' is
> not defined
>
> I've been working for hours on this stupid thing.

This compiles and passes the assert for me with v2.068.2-b1:

import std.traits;
import std.meta;

struct S { int x; float y; }
static assert(FieldNameTuple!S == AliasSeq!("x", "y"));

void main()
{}

(std.meta.AliasSeq is the new name for std.typetuple.TypeTuple but 
TypeTuple still works.)

Ali



More information about the Digitalmars-d-learn mailing list