static ref int func1(ref int a, float b, byte c) { return a; } alias adpt1 = adaptTuple!func1; auto t = tuple(4, 1.1f, cast(byte)2); assert(&adpt1(t) == &(t.field[0])); // NG; adpt1の引数がlvalueじゃない(std.forwardのような転送) static assert(!is(typeof({adpt1(tuple(4, 1.1f, cast(byte)2));}))); // naryFun & 事前に型指定あり alias adpt2 = adaptTuple!(naryFun!"a", int, float, byte); assert(&adpt2(t) == &(t.field[0])); // forward性 assert(adpt2(tuple(4, 1.1f, cast(byte)2)) == t.field[0]); // NG; stringはfloatへ暗黙変換不可能 static assert(!is(typeof({adpt2(tuple(1, "foo", cast(byte)2));}))); // OK; realはfloatへ暗黙変換可能 static assert(is(typeof({adpt2(tuple(1, 1.1L, cast(byte)2));}))); assert(adpt2(tuple(1, 1.1L, cast(byte)2)) == 1); const ct = t; static assert(is(typeof(adpt2(ct)) == const)); immutable it = t; static assert(is(typeof(adpt2(it)) == immutable)); shared st = t; static assert(is(typeof(adpt2(st)) == shared)); assert(adaptTuple!(naryFun!"a")(tuple(1, 2, 3)) == 1); assert(adaptTuple!(naryFun!"a", int)(tuple(1)) == 1);
ある関数funcの引数に、タプルを適用できるようにします。