Questions tagged [lvalue]

L-value represents the address of the value. "L" stands for the left side, because the address it is what is required when the variable appears on the left side of an assignment operation.

661 questions
7
votes
4 answers

Does the expression `new T` evaluate to an rvalue or an lvalue?

I am currently reading this tutorial/explanation of rvalue references: http://thbecker.net/articles/rvalue_references/section_07.html In the 2nd to last paragraph, the author mentions that "the argument of the copy constructor of T in the body of…
elatalhm
  • 516
  • 3
  • 12
7
votes
5 answers

When will c++11 perform move automatically when std::move is not explicitly used?

If I have a struct in which I did not provide any copy and move constructor: struct MyStruct { MyStruct() { // this is the only function ... } ... }; then if I do the following: std::vector
keelar
  • 5,814
  • 7
  • 40
  • 79
7
votes
4 answers

Why isn't the result of this cast an lvalue?

I need some advice with this strange behavior – lets have this code: int ** p; This compiles without any trouble: p++; But this: ((int**)p)++; Gives me this error message: “error: lvalue required as increment operand”. I am casting to p to the…
Pavel
  • 115
  • 5
7
votes
7 answers

Understanding the increment operator in C

Why is the following illegal in C? y = (w + x)++; According to my book, this is illegal, but I don't see why.
7
votes
2 answers

lvalue binding to rvalue reference

I am trying to understand how lvalues bind to rvalue references. Consider this code: #include template void f(T&& x) { std::cout << x; } void g(int&& x) { std::cout << x; } int main() { int x = 4; f(x); …
r.v
  • 4,697
  • 6
  • 35
  • 57
7
votes
2 answers

Eigen library: return a matrix block in a function as lvalue

I am trying to return a block of a matrix as an lvalue of a function. Let's say my function looks like this: Block getBlock(MatrixXd & m, int i, int j, int row, int column) { return m.block(i,j,row,column); } As it turns out, it seems…
HuaTham
  • 7,486
  • 5
  • 31
  • 50
7
votes
4 answers

Get the address of an Objective-c property (which is a C struct)

I have an Objective-C class which contains a C-style struct. I need to call a C function passing a pointer to this object member (a.k.a. property). For the life of me, I can't figure out how to get the address of this C struct. Using the…
jDawg
6
votes
2 answers

How to know if returning an l-value when using `FALLBACK`?

How can I know if I actually need to return an l-value when using FALLBACK? I'm using return-rw but I'd like to only use return where possible. I want to track if I've actually modified %!attrs or have only just read the value when FALLBACK was…
gdonald
  • 984
  • 2
  • 12
  • 23
6
votes
2 answers

How to efficiently bind either an lvalue or rvalue to the same reference?

Say you have a C++ function which uses an altered version of a (const) parameter. MyObject alter_obj( MyObject const & obj ); // Creates new, altered object void func( MyObject const & original ) { MyObject const & altered( alter_obj( original…
R.M.
  • 3,461
  • 1
  • 21
  • 41
6
votes
2 answers

why foo((&i)++) gives Lvalue required error. There is no array associated

I understand a few things about Lvalue but I don't understand how the below code gives an error: #include void foo(int *); int main() { int i=10; foo((&i)++); } void foo(int *p) { printf("%d",*p); } 6:13: error: lvalue…
likeicare
  • 79
  • 1
  • 9
6
votes
1 answer

Why isn't this rvalue promoted to an lvalue as specified in the reference?

The Rust Reference says: The left operand of an assignment or compound-assignment expression is an lvalue context, as is the single operand of a unary borrow. [...] When an rvalue is used in an lvalue context, a temporary un-named lvalue is created…
Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
6
votes
1 answer

Problem by a reference variable of a template parameter

The following small example shows my problem: template struct X { static void xxx(T& x) { } static void xxx(T&& x) { } }; int main(int argc, char** argv) { int x = 9; X::xxx(x); // OK. X::xxx(x); // ERROR! …
Sadeq
  • 7,795
  • 4
  • 34
  • 45
6
votes
2 answers

How to return a pointer as an iterator?

I need to implement iterators, and i don't have time to make nice iterator classes, so i have decided to just return pointers. It is something like this int* begin() { return p; } But i want them to behave as usual stl iterators *++begin(); //…
Yola
  • 18,496
  • 11
  • 65
  • 106
6
votes
1 answer

assigning to rvalue: why does this compile?

In the following example: class A { private: double content; public: A():content(0) {} A operator+(const A& other) { content += other.content; return *this; } void operator=(const A& other) { content =…
ForeverStudent
  • 2,487
  • 1
  • 14
  • 33
6
votes
1 answer

What is an unnamed lvalue?

I have seen in the draft N4268 a concept called "unnamed lvalue" in the striked-though part below [ Note: Temporaries, unnamed lvalues, and named lvalues with no linkage are A temporary object is not an acceptable template-arguments when the…
Pumkko
  • 1,523
  • 15
  • 19