Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 03, 2010 [Issue 4265] New: It should be possible to query template parameters with __traits | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4265 Summary: It should be possible to query template parameters with __traits Product: D Version: future Platform: Other OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: nfxjfg@gmail.com --- Comment #0 from nfxjfg@gmail.com 2010-06-02 20:33:10 PDT --- Consider you have struct(T1, T2) Foo { } alias Foo!(int, float) X; You should be able to extract (int, float) from X. Often it is possible to get the parameters indirectly from members, but there doesn't seem to be a way to do this in the general case. I suggest: __traits(getTemplateParameters, X) which would yield a (int, float) tuple. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 03, 2010 [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 Trass3r <mrmocool@gmx.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mrmocool@gmx.de --- Comment #1 from Trass3r <mrmocool@gmx.de> 2010-06-03 16:53:07 PDT --- What would you use that for? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 04, 2010 [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 #2 from nfxjfg@gmail.com 2010-06-03 20:05:20 PDT --- Trass3r: meta programming. It often happened to me that I wanted to get the template params. Sometimes I had to add alias declarations just to get access to them. I think this feature would make meta programming code simpler in some cases. PS: the example above should start with: struct Foo(T1, T2) { } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 04, 2010 [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 #3 from Trass3r <mrmocool@gmx.de> 2010-06-03 20:40:28 PDT --- Well of course it's for metaprogramming. But I can't imagine a usecase at the moment so I asked for some examples ;) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 07, 2011 [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 nfxjfg@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 07, 2011 [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 Brad Roberts <braddr@puremagic.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED CC| |braddr@puremagic.com Resolution|INVALID | -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 20, 2012 [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| |andrej.mitrovich@gmail.com --- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-20 14:55:16 PST --- 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 22, 2012 [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 #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-22 15:09:13 PST --- I can have a pull ready soon for 2 traits: 1. Get the template out of the template instance (Foo!int => Foo) 2. Get the arguments used to instantiate the template (Foo!int => (int)) However I need some good names for these. I thought about using '__traits(getTemplateArgs, T)' and '__traits(getTemplateParent, T)', any better suggestions? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 22, 2012 [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 #6 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-22 15:24:32 PST --- (In reply to comment #5) > I can have a pull ready soon for 2 traits: > > 1. Get the template out of the template instance (Foo!int => Foo) > 2. Get the arguments used to instantiate the template (Foo!int => (int)) > > However I need some good names for these. I thought about using > '__traits(getTemplateArgs, T)' and '__traits(getTemplateParent, T)', any better > suggestions? nazriel suggested: 'getTemplateName' 'getTemplateArgs' I think it's better because they line up nicely. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 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 Andrei Alexandrescu <andrei@erdani.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrei@erdani.com --- Comment #7 from Andrei Alexandrescu <andrei@erdani.com> 2013-03-24 05:30:25 PDT --- C++ lacks this particular ability and makes up for it by requiring templates to define internal aliases for type parameters. However, this is more tenuous for value parameters and simply impossible for template template parameters (in our case alias parameters). This has led to certain contortions and limitations; based on that experience I think we should add this ability. -- 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