On Monday, 10 October 2016 at 11:46:01 UTC, Nordlöw wrote:
At
https://github.com/nordlow/phobos-next/blob/master/src/moval.d
I've implemented a helper function for creating r-value out of
l-values defined as
E movedToRvalue(E)(ref E e)
{
import std.algorithm.mutation : move;
E value;
move(e, value); // this can be optimized
return value;
}
Doesn't the second overload of `move()` already do what you want?
https://dlang.org/phobos/std_algorithm_mutation.html#.move
Note that in your implementation, you needlessly initialize
`value`, which then needs to be properly destroyed by `move()`,
which the Phobos implementation avoids:
https://github.com/dlang/phobos/blob/master/std/algorithm/mutation.d#L1083-L1088
For the case when movedToRvalue is called with an r-value, such
as in,
static assert(__traits(compiles, { consume(S(14)); }));
I would like to overload to an identity op.
If the compiler is smart enough to understand what
`moveEmplace()` does, it could already do this automatically.