F.17: note about passing reference wrappers by value (issue #1948)

This commit is contained in:
Sergey Zubkov
2022-08-08 15:11:21 -04:00
parent 6476b15070
commit 0a7d70851c

View File

@@ -2954,6 +2954,18 @@ This makes it clear to callers that the object is assumed to be modified.
##### Note ##### Note
Some user-defined and standard library types, such as `span<T>` or the iterators
are [cheap to copy](#Rf-in) and may be passed by value, while doing so has
mutable (in-out) reference semantics:
void increment_all(span<int> a)
{
for (auto&& e : a)
++e;
}
##### Note
A `T&` argument can pass information into a function as well as out of it. A `T&` argument can pass information into a function as well as out of it.
Thus `T&` could be an in-out-parameter. That can in itself be a problem and a source of errors: Thus `T&` could be an in-out-parameter. That can in itself be a problem and a source of errors: