Bug 599 – ExpressionTuple doesn't match template's alias parameters
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2006-11-25T19:56:00Z
Last change time
2015-06-09T05:15:25Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
lovesyao
Comments
Comment #0 by lovesyao — 2006-11-25T19:56:13Z
template test2(alias s){
alias s[0] test2;
}
void test(T...)(T tl){
alias tl tl2;//ok
assert(test2!(tl)==0);//doesn't match alias template declaration
}
void main(){
test(0,"a",'a');
}
Comment #1 by smjg — 2007-09-10T05:56:15Z
Here's what I get (DMD 0.121, Windows):
bz599.d(7): template instance test2!(_param_0,_param_1,_param_2) does not match any template declaration
bz599.d(7): Error: void has no value
bz599.d(7): Error: incompatible types for ((test2!(_param_0,_param_1,_param_2)) == (0)): 'void' and 'int'
bz599.d(11): template instance bz599.test!(int,char[1u],char) error instantiating
The problem seems to be that it doesn't like a tuple as a template alias parameter. From what I can make out of the spec, it ought to work.
Comment #2 by smjg — 2007-09-10T06:11:19Z
On second thoughts, it seems the problem is that test2!(t1) expands to test2!(0, "a", 'a'), which is three parameters, whereas (alias s) is only one. Still, it ought to be possible to pass tuples as alias parameters.
Comment #3 by bugzilla — 2008-06-30T02:08:33Z
Tuples are expanded before arguments are matched to parameters, so they cannot be passed as alias parameters. This is by design.
Comment #4 by shro8822 — 2008-06-30T11:58:34Z
If you need to allow someone to do this for your template, try this:
struct Tpack(T...)
{
static alias T Tpl;
}
test2!(Tpack!(T))
template test2(alias s){
alias s.Tpl[0] test2;
}
(Or some variate of that, I didn't test this but have made the trick work before)