Created on 2007-11-28.00:00:00 last changed 186 months ago
Rationale (July, 2009):
The CWG reaffirmed its early decision. In general, templates will need to be written differently for reference and non-reference type parameters. Also, the Standard library provides a facility, std::remove_reference, that can be used easily for such cases.
Additional discussion (May, 2009):
Consider the following slightly extended version of the example above:
template <typename T> void f(T t) { T& tr = t; // OK T* tp = &t; // error auto * ap = &t; // OK! }
This means that a template that expects a reference type will need to use auto just to work around the failure to collapse pointer-to-reference types. The result might, in fact, be subtly different with auto, as well, in case there is an overloaded operator& function that doesn't return exactly T*. This contradicts one of the main goals of C++0x, to make it simpler, more consistent, and easier to teach.
Rationale (February, 2008):
In the absence of a compelling need, the CWG felt that it was better not to change the existing rules. Allowing this case could cause a quiet change to the meaning of a program, because attempting to create a pointer to a reference type is currently a deduction failure.
The Standard currently specifies (9.2.4 [dcl.typedef] paragraph 9, 13.4.2 [temp.arg.type] paragraph 4) that an attempt to create a reference to a reference (via a typedef or template type parameter) is effectively ignored. The same is not true of an attempt to form a pointer to a reference; that is, assuming that T is specified to be a reference type,
template <typename T> void f(T t) { T& tr = t; // OK T* tp = &t; // error }
It would be more consistent to allow pointers to references to collapse in the same way that references to references do.
History | |||
---|---|---|---|
Date | User | Action | Args |
2009-08-03 00:00:00 | admin | set | messages: + msg2280 |
2009-08-03 00:00:00 | admin | set | status: open -> nad |
2009-06-19 00:00:00 | admin | set | messages: + msg2113 |
2009-06-19 00:00:00 | admin | set | status: nad -> open |
2008-03-17 00:00:00 | admin | set | messages: + msg1629 |
2008-03-17 00:00:00 | admin | set | status: open -> nad |
2007-11-28 00:00:00 | admin | create |