adaptTuple

ある関数funcの引数に、タプルを適用できるようにします。

  1. auto ref adaptTuple(X arg)
    template adaptTuple(alias func, T...)
    ref
    static if(T.length > 0)
    adaptTuple
    (
    X
    )
    (
    ref X arg
    )
    if (
    is(Unqual!X : Tuple!U,
    U...
    ) &&
    )
  2. auto ref adaptTuple(X arg)
  3. auto ref adaptTuple(X arg)
  4. auto ref adaptTuple(X arg)

Members

Functions

_toRvalue
auto _toRvalue(X a)
Undocumented in source. Be warned that the author may not have intended to support it.
_toRvalueNargs
string _toRvalueNargs(size_t N)
Undocumented in source. Be warned that the author may not have intended to support it.
adaptTuple
auto ref adaptTuple(X arg)
Undocumented in source. Be warned that the author may not have intended to support it.
adaptTuple
auto ref adaptTuple(X arg)
Undocumented in source. Be warned that the author may not have intended to support it.
adaptTuple
auto ref adaptTuple(X arg)
Undocumented in source. Be warned that the author may not have intended to support it.
adaptTuple
auto ref adaptTuple(X arg)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

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);

Meta