Puppy
Puppy

Reputation: 146910

The type of auto

I'm really curious- why does auto favour value types? Surely it would be better for auto to be what auto&& is now- a reference which extends the lifetime of temporaries if necessary.

Upvotes: 1

Views: 178

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490108

"Why" questions like this are difficult (if not impossible) to answer -- even the committee members involved may easily have difficulty reconstructing the entire sequence of events that led to the decision they made.

That leads to the second point: such decisions often happen due as much to a sequence of events, as to the single "static" overall view you get from looking at the FDIS (or any other draft of the standard).

Despite the problems, you can get at least some more idea of how the decisions came about by reading proposals, counter-proposals, arguments, etc., that lead up to them. In this case, the proposal history runs something like this:

N1478 Decltype and auto
N1527 Mechanisms for querying types of expressions: Decltype and auto revisited
N1607 Decltype and auto (revision 3)
N1705 Decltype and auto (revision 4)
N1721 Deducing the type of variable from its initializer expression
N1737 A Proposal to Restore Multi-declarator auto Declarations
N1794 Deducing the type of variable from its initializer expression (revision 2)
N1894 Deducing the type of variable from its initializer expression (revision 3)
N1978 Decltype (revision 5)
N1984 *Deducing the type of variable from its initializer expression (revision 4)
N2115 Decltype (revision 6): Proposed Wording
N2337 The syntax of auto declarations
N2343 Decltype (revision 7): Proposed Wording
N2763 Unified Function Syntax
N2825 Unified Function Syntax (revision)

The proposals for decltype and auto were bifurcated around 2005, but I've included later dectype papers as well, since both deal with similar issues, and they (seem to have) tried to maintain coherency between the two.

It's not a proposal for the standard, but there's also Representing C++ Directly, Completely and Efficiently by Gabriel Dos Reis and Bjarne Stroustrup, which has some bearing on the same subject, and probably did at least a little to shape thinking on the subject.

There are undoubtedly at least a few more papers I've missed here (at least some of the rvalue reference papers are probably relevant), but these should at least be a reasonable start toward understanding how things got the way they are.

Upvotes: 6

Related Questions