Bug 16707 – [Templates] run variadic templates example failed
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-11-21T09:52:52Z
Last change time
2023-02-02T12:15:22Z
Keywords
pull, trivial
Assigned to
No Owner
Creator
panmengh
Comments
Comment #0 by panmengh — 2016-11-21T09:52:52Z
Hi, I am very new to dlang, the following example can't be compiled, my dmd version is "DMD32 D Compiler v2.072.0".
https://dlang.org/spec/template.html#variadic-templates
template print(args...)
{
void print()
{
writeln("args are ", args); // args is a ValueSeq
}
}
template write(Args...)
{
void write(Args args) // Args is a TypeSeq
// args is a ValueSeq
{
writeln("args are ", args);
}
}
void main()
{
print!(1,'a',6.8).print(); // prints: args are 1a6.8
write!(int, char, double).write(1, 'a', 6.8); // prints: args are 1a6.8
}
app.d(31): Error: template app.print cannot deduce function from argument types !()(void), candidates are:
app.d(11): app.print(args...)()
app.d(32): Error: function app.write!(int, char, double).write (int _param_0, char _param_1, double _param_2) isnot callable using argument types ()
Comment #1 by bugzilla — 2019-12-24T12:42:37Z
Should be
void main()
{
print!(1,'a',6.8)(); // prints: args are 1a6.8
write!(int, char, double)(1, 'a', 6.8); // prints: args are 1a6.8
}