Variadic function parameters passed by move
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 21 13:09:41 PST 2016
On Wednesday, December 21, 2016 20:27:47 Nordlöw via Digitalmars-d-learn
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.
Given that ref isn't involved, assuming that nothing else after the call to
g references ranges, the compiler should move the values in ranges when it
calls g, so I would have hoped that the compiler would then allow you to
call g with some of the values being non-copyable, but maybe it's not that
forgiving right now for some reason. I can't actually test anything at the
moment though, so I don't know what it will and won't actually allow you to
do - just what it should be able to allow you to do given what it does with
implicit moves.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list