Bug 3608 – Allow isExpression and templates to capture template parameters and FQN of template

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2009-12-11T07:26:00Z
Last change time
2012-05-20T14:31:26Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
simen.kjaras

Comments

Comment #0 by simen.kjaras — 2009-12-11T07:26:57Z
Currently, there is no way to extract FQN of a template from an instantiation, nor to get its parameters. This is not completely true, as one could parse its stringof representation, but this is often not enough. I therefore propose that the following syntax be allowed: template foo( T : U!( V ), U, V... ) Thus, one could get the base template or parameters of an instantiation using the following templates: template BaseTemplate( T : U!( V ), U, V... ) { alias U BaseTemplate; } template TemplateParameters( T : U!( V ), U, V... ) { alias V TemplateParameters; }
Comment #1 by simen.kjaras — 2010-11-08T05:21:14Z
Judging by the recent resolution of bug 1714, this is not so much an enhancement as a planned feature. Updating the syntax: template foo( T : U!V, alias U, V... ) { //... } template BaseTemplate( T : U!( V ), alias U, V... ) { alias U BaseTemplate; } template TemplateParameters( T : U!( V ), alias U, V... ) { alias V TemplateParameters; } This may be a separate bug, as it concerns variadic parameter lists, something bug 1714 fails to take into account.
Comment #2 by clugdbug — 2010-11-08T06:22:55Z
The patch in bug 5614 fixes some issues which seem similar to these. But I'm not sure what these test cases are supposed to do. It seems to be an attempt to use IFTI, but note that IFTI only applies to function templates. But type deduction can also be used in is() expressions.
Comment #3 by simen.kjaras — 2010-11-08T07:00:15Z
I'm not sure what it is that confuses you. D allows constraints to be placed on template parameters not only by means of template constraints, but also isExpression-like patterns in the parameter list: class A {} class B : A {} template isAnA( T : A ) { enum isAnA = true; } static assert( isAnA!B ); This also works for more complex type constraints: template extractTupleArgs( T == Tuple!U, U... ) { alias U extractTupleArgs; } static assert( is( extractTupleArgs!( Tuple!int ) == int ) ); It does however not work for complex type constraints where the template is not known: template dissectTemplate( T == U!V, V... ) { alias U tmpl; alias V args; } And it is this last case I want covered.
Comment #4 by simen.kjaras — 2010-11-08T07:02:15Z
(In reply to comment #3) > template dissectTemplate( T == U!V, V... ) { This should of course be template dissectTemplate( T == U!V, alias U, V... ) {
Comment #5 by k.hara.pg — 2012-05-20T09:51:48Z
Comment #6 by github-bugzilla — 2012-05-20T12:48:06Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b327dd61e685c85adfdceef0767b4a456350667b fix Issue 3608 - Allow isExpression and templates to capture template parameters and FQN of template https://github.com/D-Programming-Language/dmd/commit/ed68238cd1e5a7aec454840ee11e04580f974855 Merge pull request #958 from 9rnsr/fix_tided Issue 1780 & 3608 & 8125 - Fix TypeInstance deduction problems