mirror of
https://github.com/dlang/dmd.git
synced 2025-04-25 20:50:41 +03:00
add __rvalue(expression) builtin (#17050)
This commit is contained in:
parent
13775eb2d1
commit
a99a3894be
31 changed files with 471 additions and 163 deletions
23
changelog/dmd.rvalue.dd
Normal file
23
changelog/dmd.rvalue.dd
Normal file
|
@ -0,0 +1,23 @@
|
|||
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.
|
Loading…
Add table
Add a link
Reference in a new issue