Created on 2006-12-01.00:00:00 last changed 33 months ago
[Voted into the WP at the September, 2008 meeting as part of paper N2757.]
Proposed resolution (August, 2008):
Change 13.10.3.2 [temp.deduct.call] paragraph 3 as follows:
If P is
an rvalue reference typeof the form T&&, where T is a template parameter, and the argument is an lvalue, the type A& is used in place of A for type deduction. [Example:template <typename T> int f(T&&); int i; int j = f(i); // calls f<int&>(i) template <typename T> int g(const T&&); int k; int n = g(k); // calls g<int>(k)—end example]
[Note: The effect of this rule for lvalue arguments and rvalue reference parameters is that deduction in such cases will fail unless the function parameter is of the form cv T&& (13.10.3.6 [temp.deduct.type]). —end note]
Suggested resolution:
Change 13.10.3.2 [temp.deduct.call] paragraph 3 as follows:
If P is
an rvalue reference typeof the form T&&, where T is a template parameter, and the argument is an lvalue,the type A& is used in place of A for type deductionT is deduced as A&. [Example:template <typename T> int f(T&&); int i; int j = f(i); // calls f<int&>(i) template <typename T> int g(const T&&); int k; int n = g(k); // calls g<int>(k)—end example]
[Note: The effect of this rule for lvalue arguments and rvalue reference parameters is that deduction in such cases will fail unless the function parameter is of the form cv T&& (13.10.3.6 [temp.deduct.type]). —end note]
There are a couple of minor problems with the rvalue reference wording in the WP. The non-normative note in 13.10.3.2 [temp.deduct.call] paragraph 3 says,
[Note: The effect of this rule for lvalue arguments and rvalue reference parameters is that deduction in such cases will fail unless the function parameter is of the form cv T&& (13.10.3.6 [temp.deduct.type]). —end note]
It turns out that this isn't correct. For example:
template <class T> void g(basic_string<T> && ); ... basic_string<char> s; g(s); // Note says that it should fail, we want it to call // g<char>(basic_string<char>&&)
Additionally, consider this case:
template <class T> void f(const T&&); ... int i; f(i);
If we deduce T as int& in this case then f(i) calls f<int&>(int&), which seems counterintuitive. We prefer that f<int>(const int&&) be called. Therefore, we would like the wording clarified that the A& deduction rule in 13.10.3.2 [temp.deduct.call] paragraph 3 applies only to the form T&& and not to cv T&& as the note currently implies.
These are minor tweaks to the rvalue reference wording and a fallout from issue 540. In particular, the major applications of move semantics and perfect forwarding are not impacted with respect to the original intentions of the rvalue reference work by these suggestions.
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-02-18 07:47:23 | admin | set | messages: + msg6696 |
2008-10-05 00:00:00 | admin | set | messages: + msg1831 |
2008-10-05 00:00:00 | admin | set | status: review -> cd1 |
2008-08-25 00:00:00 | admin | set | messages: + msg1746 |
2008-08-25 00:00:00 | admin | set | status: drafting -> review |
2008-03-17 00:00:00 | admin | set | status: open -> drafting |
2006-12-01 00:00:00 | admin | create |