Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
October 10, 2016 isRvalue trait | ||||
---|---|---|---|---|
| ||||
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? |
October 10, 2016 Re: isRvalue trait | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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 |
October 10, 2016 Re: isRvalue trait | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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=15634 Ok, 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? |
October 10, 2016 Re: isRvalue trait | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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. |
October 10, 2016 Re: isRvalue trait | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On Monday, 10 October 2016 at 12:22:54 UTC, Marc Schütz wrote:
>> 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.
Doh! My mistake.
I'll use `moveEmplace`, then.
Thx!
|
Copyright © 1999-2021 by the D Language Foundation