mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Reworded "consume" to "will-move-from" parameters
To improve clarity since the wording was causing confusion
This commit is contained in:
parent
99b997b6f0
commit
cea965f610
|
@ -2285,7 +2285,7 @@ Parameter passing expression rules:
|
|||
* [F.15: Prefer simple and conventional ways of passing information](#Rf-conventional)
|
||||
* [F.16: For "in" parameters, pass cheaply-copied types by value and others by reference to `const`](#Rf-in)
|
||||
* [F.17: For "in-out" parameters, pass by reference to non-`const`](#Rf-inout)
|
||||
* [F.18: For "consume" parameters, pass by `X&&` and `std::move` the parameter](#Rf-consume)
|
||||
* [F.18: For "will-move-from" parameters, pass by `X&&` and `std::move` the parameter](#Rf-consume)
|
||||
* [F.19: For "forward" parameters, pass by `TP&&` and only `std::forward` the parameter](#Rf-forward)
|
||||
* [F.20: For "out" output values, prefer return values to output parameters](#Rf-out)
|
||||
* [F.21: To return multiple "out" values, prefer returning a tuple or struct](#Rf-out-multi)
|
||||
|
@ -2835,7 +2835,7 @@ For advanced uses (only), where you really need to optimize for rvalues passed t
|
|||
|
||||
* If the function is going to unconditionally move from the argument, take it by `&&`. See [F.18](#Rf-consume).
|
||||
* If the function is going to keep a copy of the argument, in addition to passing by `const&` (for lvalues),
|
||||
add an overload that passes the parameter by `&&` (for rvalues) and in the body `std::move`s it to its destination. Essentially this overloads a "consume"; see [F.18](#Rf-consume).
|
||||
add an overload that passes the parameter by `&&` (for rvalues) and in the body `std::move`s it to its destination. Essentially this overloads a "will-move-from"; see [F.18](#Rf-consume).
|
||||
* In special cases, such as multiple "input + copy" parameters, consider using perfect forwarding. See [F.19](#Rf-forward).
|
||||
|
||||
##### Example
|
||||
|
@ -2845,7 +2845,7 @@ For advanced uses (only), where you really need to optimize for rvalues passed t
|
|||
// suffix is input-only but not as cheap as an int, pass by const&
|
||||
string& concatenate(string&, const string& suffix);
|
||||
|
||||
void sink(unique_ptr<widget>); // input only, and consumes the widget
|
||||
void sink(unique_ptr<widget>); // input only, and moves ownership of the widget
|
||||
|
||||
Avoid "esoteric techniques" such as:
|
||||
|
||||
|
@ -2918,7 +2918,7 @@ A bad logic error can happen if the writer of `g()` incorrectly assumes the size
|
|||
* (Moderate) ((Foundation)) Warn about functions regarding reference to non-`const` parameters that do *not* write to them.
|
||||
* (Simple) ((Foundation)) Warn when a non-`const` parameter being passed by reference is `move`d.
|
||||
|
||||
### <a name="Rf-consume"></a>F.18: For "consume" parameters, pass by `X&&` and `std::move` the parameter
|
||||
### <a name="Rf-consume"></a>F.18: For "will-move-from" parameters, pass by `X&&` and `std::move` the parameter
|
||||
|
||||
##### Reason
|
||||
|
||||
|
@ -9349,7 +9349,7 @@ Using `unique_ptr` in this way both documents and enforces the function call's o
|
|||
|
||||
##### Example
|
||||
|
||||
void sink(unique_ptr<widget>); // consumes the widget
|
||||
void sink(unique_ptr<widget>); // takes ownership of the widget
|
||||
|
||||
void uses(widget*); // just uses the widget
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user