Thread overview | |||||
---|---|---|---|---|---|
|
October 16, 2013 how to pass multiple arguments via a mixin | ||||
---|---|---|---|---|
| ||||
Attachments:
| is there a general solution to pass multiple arguments to a function via a mixin? see below for a partial solution using Alias, which fails for the last case below: void main(){ import std.stdio; string a="A"; string b="B"; writeln(a,b);// OK (prints "AB") writeln(&a,&b);//OK (prints both addresses) writeln(mixin(`a,b`));//prints "B" import std.typetuple; writeln(mixin(`Alias!(a,b)`));//OK:prints "AB" //writeln(mixin(`Alias!(&a,&b)`));//CT Error: expression & a is not a valid template value argument } |
October 16, 2013 Re: how to pass multiple arguments via a mixin | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timothee Cour | On Wednesday, 16 October 2013 at 00:36:46 UTC, Timothee Cour wrote: > ... Have you tried run-time tuple? ``` import std.typecons; writeln(mixin("tuple(&a,&b).expand")); ``` |
October 16, 2013 Re: how to pass multiple arguments via a mixin | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot Attachments:
| doesn't work with ref args: void fun(ref int a,ref int b){ a=1; } void main(){ int a,b; import std.typecons; fun(mixin("tuple(a,b).expand")); assert(a==1);//fails } and we can't do a logic such as: if there's ref args use Alias, otherwise use tuple().expand because there could be a mix of the two On Tue, Oct 15, 2013 at 5:56 PM, Dicebot <public@dicebot.lv> wrote: > On Wednesday, 16 October 2013 at 00:36:46 UTC, Timothee Cour wrote: > >> ... >> > > Have you tried run-time tuple? > > ``` > import std.typecons; > writeln(mixin("tuple(&a,&b).**expand")); > ``` > |
Copyright © 1999-2021 by the D Language Foundation