www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to pass multiple arguments via a mixin

reply Timothee Cour <thelastmammoth gmail.com> writes:
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
}
Oct 15 2013
parent reply "Dicebot" <public dicebot.lv> writes:
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")); ```
Oct 15 2013
parent Timothee Cour <thelastmammoth gmail.com> writes:
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")); ```
Oct 15 2013