dimanche 10 juin 2018

What does it mean "xvalue has identity"?

C++11 introduced new value categories, one of them is xvalue.

It is explained by Stroustrup as something like (im category): "it is a value, which has identity, but can be moved from".

Another source, cppreference explains:

a glvalue is an expression whose evaluation determines the identity of an object, bit-field, or function;

And xvalue is a glvalue, so this is statement is true for xvalue too.

Now, I thought that if an xvalue has identity, then I can check if two xvalues refer to the same object, so I take the address of an xvalue. As it turned out, it is not allowed:

int main() {
    int a;
    int *b = &std::move(a); // NOT ALLOWED
}

What does it mean that xvalue has identity?

Aucun commentaire:

Enregistrer un commentaire