什么是未命名的左值?
What is an unnamed lvalue?
我在草稿N4268下面的划线部分看到了一个叫做"unnamed lvalue"的概念
[ Note: Temporaries, unnamed lvalues, and named lvalues with no linkage are A temporary object is not an acceptable template-arguments when the corresponding template-parameter has reference type. [ Example: ... ] ]
我搜索了很多,但 Whosebug 和 google 都没有给我答案。
我只找到这个 post 关于值类别
What are rvalues, lvalues, xvalues, glvalues, and prvalues
但是没有用。
并不是所有的左值表达式都有名字。其实N4296中的写法给我们举了一些例子:
For a non-type template-parameter of reference or pointer type, the
value of the constant expression shall not refer to (or for a pointer
type, shall not be the address of):
- a subobject (1.8),
- a temporary object (12.2),
- a string literal (2.14.5),
- the result of a typeid expression (5.2.8), or
- a predefined func variable (8.4.1).
此外,cppreference关于值类别的信息详细介绍了左值:
An lvalue is an expression that identifies a non-temporary object or a
non-member function.
The following expressions are lvalues:
The name of a variable or function in scope, regardless of type, such as std::cin or std::endl. Even if the variable's type is rvalue
reference, the expression consisting of its name is an lvalue
expression.
Function call or overloaded operator expression if the function's or overloaded operator's return type is an lvalue reference, such as
std::getline(std::cin, str) or std::cout << 1 or str1 = str2 or ++iter
Built-in pre-increment and pre-decrement, dereference, assignment and compound assignment, subscript (except on an array xvalue), member
access (except for non-static non-reference members of xvalues, member
enumerators, and non-static member functions), member access through
pointer to data member if the left-hand operand is lvalue, comma
operator if the right-hand operand is lvalue, ternary conditional if
the second and third operands are lvalues.
Cast expression to lvalue reference type.
String literal
然而,这一切都无关紧要,因为更改的范围是提案 Allow constant evaluation for all non-type template arguments。
我在草稿N4268下面的划线部分看到了一个叫做"unnamed lvalue"的概念
[ Note:
Temporaries, unnamed lvalues, and named lvalues with no linkage areA temporary object is not an acceptable template-arguments when the corresponding template-parameter has reference type. [ Example: ... ] ]
我搜索了很多,但 Whosebug 和 google 都没有给我答案。 我只找到这个 post 关于值类别
What are rvalues, lvalues, xvalues, glvalues, and prvalues
但是没有用。
并不是所有的左值表达式都有名字。其实N4296中的写法给我们举了一些例子:
For a non-type template-parameter of reference or pointer type, the value of the constant expression shall not refer to (or for a pointer type, shall not be the address of):
- a subobject (1.8),
- a temporary object (12.2),
- a string literal (2.14.5),
- the result of a typeid expression (5.2.8), or
- a predefined func variable (8.4.1).
此外,cppreference关于值类别的信息详细介绍了左值:
An lvalue is an expression that identifies a non-temporary object or a non-member function.
The following expressions are lvalues:
The name of a variable or function in scope, regardless of type, such as std::cin or std::endl. Even if the variable's type is rvalue reference, the expression consisting of its name is an lvalue expression.
Function call or overloaded operator expression if the function's or overloaded operator's return type is an lvalue reference, such as std::getline(std::cin, str) or std::cout << 1 or str1 = str2 or ++iter
Built-in pre-increment and pre-decrement, dereference, assignment and compound assignment, subscript (except on an array xvalue), member access (except for non-static non-reference members of xvalues, member enumerators, and non-static member functions), member access through pointer to data member if the left-hand operand is lvalue, comma operator if the right-hand operand is lvalue, ternary conditional if the second and third operands are lvalues.
Cast expression to lvalue reference type.
String literal
然而,这一切都无关紧要,因为更改的范围是提案 Allow constant evaluation for all non-type template arguments。