digitalmars.D.learn - isRvalue trait
- =?UTF-8?B?Tm9yZGzDtnc=?= (19/19) Oct 10 2016 At
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/5) Oct 10 2016 Found it:
- =?UTF-8?B?Tm9yZGzDtnc=?= (7/10) Oct 10 2016 Ok, so I added `isLvalue` and `isRvalue` to
- Marc =?UTF-8?B?U2Now7x0eg==?= (9/24) Oct 10 2016 Doesn't the second overload of `move()` already do what you want?
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/7) Oct 10 2016 Doh! My mistake.
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; } 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. Is this currently possible somehow? I cannot find any trait `isRvalue` that fulfills static assert(isRvalue!(S(14))); Is there one?
Oct 10 2016
On Monday, 10 October 2016 at 11:46:01 UTC, Nordlöw wrote:Is there one?Found it: http://forum.dlang.org/post/n8m8bh$2vgc$1 digitalmars.com https://issues.dlang.org/show_bug.cgi?id=15634
Oct 10 2016
On Monday, 10 October 2016 at 11:51:09 UTC, Nordlöw wrote:Found it: http://forum.dlang.org/post/n8m8bh$2vgc$1 digitalmars.com https://issues.dlang.org/show_bug.cgi?id=15634Ok, so I added `isLvalue` and `isRvalue` to https://github.com/nordlow/phobos-next/blob/master/src/moval.d Now the next follow-up question becomes how to use it to restrict/overload my definition of `movedToRvalue()` since `isLvalue` takes an alias as argument and `movedToRvalue` takes a reference to an instance. How to solve this?
Oct 10 2016
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-L1088For 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.
Oct 10 2016
On Monday, 10 October 2016 at 12:22:54 UTC, Marc Schütz wrote:Doh! My mistake. I'll use `moveEmplace`, then. Thx!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.
Oct 10 2016