Frage bzgl. L-und R-Wert-Referenzen und Operaten





  • @tes32 sagte in Frage bzgl. L-und R-Wert-Referenzen und Operaten:

    #include "VektorClass.h"
    

    Ich weiß nicht, wozu wir das brauchen?

    Du hast zwei Beispiele gebracht:

    1. int func(int &a){ return a; }
      
      // ...
      
      int b;
      int &&c = func(b);
      

    und

    1. int& func(int &a) { return a; }
      
      // ...
      
      int b;
      // int &c = b;  // die Zeile ist überflüssig. Läuft aufs selbe raus wenn wir
      int d { func(b) };  // hier gleich b an func() übergeben.
      

    ´
    Ja, in 1. ist func(b) ein prvalue.

    In 2.

    Every expression belongs to exactly one of the fundamental classifications in this taxonomy: lvalue, xvalue, or prvalue.


    Hm. lvalue?

    An lvalue is a glvalue that is not an xvalue.

    Maybe Baby. (Wegen @SeppJ darf ich keine OT Witze mehr machen. Dann eben OnTopic ^^)


    glvalue?

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

    Si. Eine Referenz auf ein Objekt bestimmt seine Identität.


    xvalue?

    (4.1) the result of calling a function, whether implicitly or explicitly, whose return type is an rvalue reference to object type ([expr.call]),

    Nope.

    (4.2) a cast to an rvalue reference to object type ([expr.dynamic.cast], [expr.static.cast], [expr.reinterpret.cast], [expr.const.cast], [expr.cast]),

    Nope.

    (4.3) a subscripting operation with an xvalue array operand ([expr.sub]),

    Nope.

    (4.4) a class member access expression designating a non-static data member of non-reference type in which the object expression is an xvalue ([expr.ref]), or

    Nope.

    (4.5) a .* pointer-to-member expression in which the first operand is an xvalue and the second operand is a pointer to data member ([expr.mptr.oper]).

    Nope.


    Kein xvalue also lvalue.


    (Ich hoffe die letzten 5 genannten Punkte werden normativ. Sonst wirds echt schwer zu argumentieren 😕 )

    Was ich mich die ganze Zeit frage: Was bringt dir dieses Wissen nun? Das einzig spannende daran ist RVO. IIRC hat sich das zwischen C++11 und C++17 nochmal geändert.

    // edit: Vielleicht hilft dir der Artikel von Barry Revzin. (Inklusive Code um die Value Category einer Expression zu bestimmen.)



  • @Swordfish Ok, vielen Dank, dann sind mir einige Dinge klarer geworden. 🙂


Anmelden zum Antworten