gpt4 book ai didi

c++ - 什么是未命名的左值?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:34:04 26 4
gpt4 key购买 nike

我在草稿里看到了N4268下面划线部分的一个叫做“未命名左值”的概念

[ 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: ... ] ]

我搜索了很多,但 stackoverflow 和 google 都没有给我答案。我只找到这篇关于值(value)类别的帖子

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 .

关于c++ - 什么是未命名的左值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31448845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com