anancds / document

MIT License
1 stars 0 forks source link

左值和右值 #140

Open anancds opened 3 years ago

anancds commented 3 years ago

image

anancds commented 3 years ago

has identity? —— 是否有唯一标识,比如地址、指针。有唯一标识的表达式在 C++ 中被称为 glvalue(generalized lvalue)。 can be moved from? —— 是否可以安全地移动(编译器)。可以安全地移动的表达式在 C++ 中被成为 rvalue。

anancds commented 3 years ago

has identity and cannot be moved from - 这类表达式在 C++ 中被称为 lvalue。 has identity and can be moved from - 这类表达式在 C++ 中被成为 xvalue(expiring value)。 does not have identity and can be moved from - 这类表达式在 C++ 中被成为 prvalue(pure rvalue)。 does not have identity and cannot be moved -C++ 中不存在这类表达式。 简单总结一下这些 value categories 之间的关系:

可以移动的值都叫 rvalue,包括 xvalue 和 prvalue。 有唯一标识的值都叫 glvalue,包括 lvalue 和 xvalue。 std::move 的作用就是将一个 lvalue 转换成 xvalue。