Variadic function parameters passed by move

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 21 13:02:17 PST 2016


On 12/21/2016 12:27 PM, Nordlöw wrote:
> If I have a variadic function
>
> f(Rs...)(Rs ranges)
> {
>     g(ranges);
> }
>
> that calls
>
> g(Rs...)(Rs ranges)
> {
>     // use ranges
> }
>
> and all or some of the elements in `ranges` are non-copyable can I
> somehow move them at the call of `g` inside of `f`.
>
> I've tried
>
> f(Rs...)(Rs ranges)
> {
>     import std.algorithm.mutation : move;
>     g(move(ranges));
> }
>
> but that does't work.

At least compiles. :)

void f(Rs...)(Rs ranges)
{
     import std.functional: forward;
     g(forward!ranges);
}

void g(Rs...)(Rs ranges)
{
     // use ranges
}

struct S {
     @disable this(this);
}

void main() {
     f(1, S());
}

Ali



More information about the Digitalmars-d-learn mailing list