Named arguments

jmh530 john.michael.hall at gmail.com
Fri Oct 27 12:26:27 UTC 2017


On Friday, 27 October 2017 at 06:45:03 UTC, Jacob Carlborg wrote:
> On 2017-10-25 16:58, jmh530 wrote:
>
>> You're passing the function arguments as template parameters. 
>> Usually you want them to be able to be passed at run-time.
>
> No problem:
>
> $ cat main.d
>
> import std.stdio;
>
> void foo(args...)()
> {
>     writeln(args);
> }
>
> void main(string[] args)
> {
>     foo!(args);
> }
>
> $ dmd main.d
> $ ./main foo bar
> ["./main", "foo", "bar"]

Color me surprised. Even the below compiles and runs without error

import std.stdio;

void foo(args...)()
{
     writeln(args);
}

void main()
{
     int x1 = 1;
     int x2 = x1 + 1;
     foo!(x1, x2);
}




More information about the Digitalmars-d mailing list