C++ Style Guide: Incorrect information about rvalue references
- Dominant language
- HTML
- Stars
- 39.6k
- Forks
- 12.9k
- Avg merge
- 42m
- Merged PRs (30d)
- 15
Description
> Rvalue references are a type of reference that can only bind to temporary objects.
This is only partially correct.
Temporaries can bind to either `value const&` or `value_type&&`. The difference being, rvalue references are mutable and can bind to temporaries.
Rvalue references also bind entirely to rvalues.
Consider,
```
std::string str = "kitty cat";
std::string&& s = std::move(str);
```
Here you can see, `str` is not a temporary but rather, `std::move(str)` is an xvalue expression which has identity.
The wording should be changed to something such as,
Rvalue references are mutable references that represent resource reuse, i.e. the contents of the class are expected to be safely pilfered by consuming.
It's important to note that both xvalue and prvalue expressions are rvalue'd.
Contributor guide
Assessment
This issue has not been assessed yet.