Thread overview
how to pass multiple arguments via a mixin
Oct 16, 2013
Timothee Cour
Oct 16, 2013
Dicebot
Oct 16, 2013
Timothee Cour
October 16, 2013
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
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
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"));
> ```
>