[Issue 16707] New: [Templates] run variadic templates example failed

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Nov 21 01:52:52 PST 2016


https://issues.dlang.org/show_bug.cgi?id=16707

          Issue ID: 16707
           Summary: [Templates] run variadic templates example failed
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: normal
          Priority: P3
         Component: dlang.org
          Assignee: nobody at puremagic.com
          Reporter: panmengh at gmail.com

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 ()

--


More information about the Digitalmars-d-bugs mailing list