This post reflects my current level of understanding of a value category.
Value category is a property of an expression. Type is a propetry of a variable.
Let's say we have the following declaration:
int x;
What is x? It is a variable and it is an expression.
Writing a new syntax like this:
int&& ref
instead of
int& ref
makes people think that we've done something related to types, but actually we've done something related to expressions, not types. (We've specified what expressions can be bound to these variables.)
Probably distinguishing between "temporaries" and "non-temporaries" could be done another way, maybe something like this:
void func(int&); // for "non-temporaries"
void func((int&)); // for "temporaries
or some other way, but not fiddling with types.
So my question is: Is it necessary to encode information about an expression category into a syntax for types? What were the reasons for this design decision?
Aucun commentaire:
Enregistrer un commentaire