Hi,

I'd like to propose that rvalue references and move semantics are now 
considered permitted in the style guide. This change would allow for move 
constructors to be written. This enables more performant code, if the move ctr 
is less expensive than the copy ctr, but also more correct code. For the latter 
part, look at "8314571: GrowableArray should move its old data and not copy 
it". Here we can avoid using copy assignment, instead using move constructors, 
which more accurately reflects what is happening: The old elements are in fact 
moved, and not copied.

Two useful std functions will become available to us with this change:

1. `std::move`, for explicitly moving a value. This is a slightly more powerful 
`static_cast<T&&>(T)`, in that it also handles `T&` corectly.
2. `std::forward`, which simplifies the usage of perfect forwarding. Perfect 
forwarding is a technique where in copying is minimized. To quote Scott Meyers 
( 
https://cppandbeyond.com/2011/04/25/session-announcement-adventures-in-perfect-forwarding/
 ):

> Perfecting forwarding is an important C++0x technique built atop rvalue 
> references.  It allows move semantics to be automatically applied, even when 
> the source and the destination of a move are separated by intervening 
> function calls.  Common examples include constructors and setter functions 
> that forward arguments they receive to the data members of the class they are 
> initializing or setting, as well as standard library functions like 
> make_shared, which “perfect-forwards” its arguments to the class constructor 
> of whatever object the to-be-created shared_ptr is to point to. 

Looking forward to your feedback, thank you.
Johan

-------------

Commit messages:
 - Also update html
 - Move over Rvalue references and move semantics to permitted features

Changes: https://git.openjdk.org/jdk/pull/15386/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15386&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8314644
  Stats: 8 lines in 2 files changed: 5 ins; 3 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/15386.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15386/head:pull/15386

PR: https://git.openjdk.org/jdk/pull/15386

Reply via email to