forward

Forwards function arguments with saving ref-ness.

Members

Aliases

arg
alias arg = args[0]
Undocumented in source.
forward
alias forward = expressionTuple!()
Undocumented in source.
forward
alias forward = expressionTuple!(fwd, forward!(args[1..$]))
Undocumented in source.
fwd
alias fwd = arg
Undocumented in source.

Properties

fwd
fwd [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

int foo(int n) { return 1; }
int foo(ref int n) { return 2; }
int bar()(auto ref int x) { return foo(forward!x); }

assert(bar(1) == 1);
int i;
assert(bar(i) == 2);
void foo(int n, ref string s) { s = null; foreach (i; 0..n) s ~= "Hello"; }

// forwards all arguments which are bound to parameter tuple
void bar(Args...)(auto ref Args args) { return foo(forward!args); }

// forwards all arguments with swapping order
void baz(Args...)(auto ref Args args) { return foo(forward!args[$/2..$], forward!args[0..$/2]); }

string s;
bar(1, s);
assert(s == "Hello");
baz(s, 2);
assert(s == "HelloHello");

Note: This is just a copy of $(STDREF algorithm, _forward) implementation except it uses fixed move.

Meta