mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
23 lines
775 B
Text
23 lines
775 B
Text
Add primary expression of the form `__rvalue(expression)` which causes `expression` to be treated as an rvalue, even if it is an lvalue.
|
|
|
|
Overloads on `ref`:
|
|
```
|
|
foo(S s); // selected if `s` is an rvalue
|
|
foo(ref S s); // selected if argument `s` is an lvalue
|
|
|
|
S s;
|
|
S bar();
|
|
...
|
|
foo(s); // selects foo(ref S)
|
|
foo(bar()); // selects foo(S)
|
|
```
|
|
With this change,
|
|
```
|
|
foo(__rvalue(s)); // selects foo(S)
|
|
```
|
|
This also applies to constructors and assignments, meaning move constructors and
|
|
move assignments are enabled. Moving instead of copying can be much more resource
|
|
efficient, as, say, a string can be moved rather than copied/deleted.
|
|
|
|
A moved object can still be destructed, so take that into account when moving
|
|
a field - set it to a benign value that can be destructed.
|