April 06, 2013 [Issue 4265] It should be possible to query template parameters with __traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to nfxjfg@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=4265 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |k.hara.pg@gmail.com --- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-04-06 06:40:55 PDT --- (In reply to comment #5) > I can have a pull ready soon for 2 traits: I managed to lose the branch where I implemented this. I think I only did it partially though. @kenji: If you have this: template T(Args...) { } struct S(Args...) { } alias Tint = T!int; alias Sint = S!int; How do you get to the 'S' declaration from the instance? I want to implement these traits: static assert(is(__traits(getTemplateSymbol, SInt) == S)); static assert(is(__traits(getTemplateArgs, SInt) == int)); I've tried this in traits.c: Dsymbol *s = getDsymbol(o); TemplateInstace *ti = s->isTemplateInstance(); However that only works for Tint, and not for Sint. 's' is actually a StructDeclaration for Sint, not a TemplateInstance. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 24, 2013 [Issue 4265] It should be possible to query template parameters with __traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to nfxjfg@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=4265 thelastmammoth@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |thelastmammoth@gmail.com --- Comment #9 from thelastmammoth@gmail.com 2013-06-23 18:26:08 PDT --- (In reply to comment #4) > As a partial workaround if you know the original template a type was instantiated with you can use: > > struct Foo(T1, T2) > { > } > > alias Foo!(int, float) X; > > template GetParams(R, alias X) > { > static if (is(R x == X!T, T...)) > { > alias T GetParams; > } > } > > void main() > { > pragma(msg, GetParams!(X, Foo)); > } > > There's also an 'isTemplateInstance' now in std.traits. I don't see it ? But I added it in https://github.com/D-Programming-Language/phobos/pull/1367. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 24, 2013 [Issue 4265] It should be possible to query template parameters with __traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to nfxjfg@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=4265 --- Comment #10 from thelastmammoth@gmail.com 2013-06-23 18:27:31 PDT --- (In reply to comment #8) > (In reply to comment #5) > > I can have a pull ready soon for 2 traits: > > I managed to lose the branch where I implemented this. I think I only did it partially though. > > @kenji: If you have this: > > template T(Args...) { } > struct S(Args...) { } > alias Tint = T!int; > alias Sint = S!int; > > How do you get to the 'S' declaration from the instance? I want to implement these traits: > > static assert(is(__traits(getTemplateSymbol, SInt) == S)); > static assert(is(__traits(getTemplateArgs, SInt) == int)); > > I've tried this in traits.c: > > Dsymbol *s = getDsymbol(o); > TemplateInstace *ti = s->isTemplateInstance(); > > However that only works for Tint, and not for Sint. 's' is actually a StructDeclaration for Sint, not a TemplateInstance. I made a pull request for this and other traits. It's in std.traits, which IMO is better than adding it to the compiler. https://github.com/D-Programming-Language/phobos/pull/1367 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 25, 2013 [Issue 4265] It should be possible to query template parameters with __traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to nfxjfg@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=4265 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #11 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-08-25 15:57:09 PDT --- *** Issue 10890 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation