Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
September 19, 2015 This is probably trivial or impossible Code Introspection... | ||||
---|---|---|---|---|
| ||||
given some struct: writeln("face.glyph.bitmap = ", face.glyph.bitmap); which displays the following: face.glyph.bitmap = FT_Bitmap(30, 25, 25, 4105948, 256, 2, 0, null) Is there a way for D to display the variable names within the FT_Bitmap? For instance, the following code snippet outputs: foreach (i, member; face.glyph.bitmap.tupleof) { writefln("Member %s:", i); writefln(" type : %s", typeof(member).stringof); writefln(" value: %s", member); } Member 0: type : int value: 30 Member 1: type : int value: 25 // dot...dot...dot Member 6: type : byte value: 0 Member 7: type : void* value: null So I've got type and value of each member, but I want their actual names? My first naive attempt was to try member.stringof but this just returns the string "member". Thanks. |
September 19, 2015 Re: This is probably trivial or impossible Code Introspection... | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | 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. |
September 20, 2015 Re: This is probably trivial or impossible Code Introspection... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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.
|
September 20, 2015 Re: This is probably trivial or impossible Code Introspection... | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | 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
|
September 20, 2015 Re: This is probably trivial or impossible Code Introspection... | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | On Sun, Sep 20, 2015 at 05:21:03AM +0000, WhatMeWorry via Digitalmars-d-learn wrote: [...]
> 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"));
You need to use is(...) when comparing types:
static assert(is(FieldNameTuple!S == TypeTuple!("x", "y")));
HTH,
--T
|
September 20, 2015 Re: This is probably trivial or impossible Code Introspection... | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On 09/19/2015 10:30 PM, H. S. Teoh via Digitalmars-d-learn wrote: > On Sun, Sep 20, 2015 at 05:21:03AM +0000, WhatMeWorry via Digitalmars-d-learn wrote: > [...] >> 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")); > > You need to use is(...) when comparing types: > > static assert(is(FieldNameTuple!S == TypeTuple!("x", "y"))); > > HTH, > > > --T > True but ever-confusingly, they are not types. :) It works without the is expression. Otherwise, we need to add typeofs as well: static assert(is(typeof(FieldNameTuple!S) == typeof(AliasSeq!("x", "y")))); Ali |
September 20, 2015 Re: This is probably trivial or impossible Code Introspection... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Sunday, 20 September 2015 at 05:50:16 UTC, Ali Çehreli wrote: > On 09/19/2015 10:30 PM, H. S. Teoh via Digitalmars-d-learn wrote: >> On Sun, Sep 20, 2015 at 05:21:03AM +0000, WhatMeWorry via Digitalmars-d-learn wrote: >> [...] >>> 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")); >> >> You need to use is(...) when comparing types: >> >> static assert(is(FieldNameTuple!S == TypeTuple!("x", "y"))); >> >> HTH, >> >> >> --T >> > > True but ever-confusingly, they are not types. :) It works without the is expression. Otherwise, we need to add typeofs as well: > > static assert(is(typeof(FieldNameTuple!S) == typeof(AliasSeq!("x", "y")))); > > Ali Should of tried this earlier, but just for grins I threw in another trait: EnumMembers. import std.traits; struct S { int x; float y; } static assert(FieldNameTuple!S == TypeTuple!("x", "y")); // FAILS enum E : int { a, b, c } int[] abc = cast(int[]) [ EnumMembers!E ]; // WORKS The EnumMembers from traits compiles/links fine. Ergo, it must be I've got an old version of D Lib? I see on the web site that D Lib is now at 2.068.1 Looking at my old folders, I see a dmd-2.066_0-OneClickWindowInstaller folder that I must of used around October 2014 for my initial install. Is there a tool or subsystem that I can use to see the history or FildNameTyple? Now, I need to figure out how to upgrade my D, DMD or Phobos (not sure about terminology) without disturbing my Visual D environment. Wish me luck :) Thanks for helping me with these beginner questions. |
Copyright © 1999-2021 by the D Language Foundation