rvalue

Are std::streams already movable?

GNU gcc 4.3 partially supports the upcoming c++0x standard: among the implemented features the rvalue reference. By means of the rvalue reference it should be possible to move a non-copyable object or return it from a function. Are std::streams already movable by means of rvalue reference or does the current library implementation lack...

Why is ++i considered an l-value, but i++ is not?

Why is ++i is l-value? and i++ not Initially there were 2 questions one was removed since that was exact duplicate. So don't down vote the answers that were answering difference between pre- and post-increment. ...

Why are C++0x rvalue reference not the default?

One of the cool new features of the upcoming C++ standard, C++0x, are "rvalue references." An rvalue reference is similar to an lvalue (normal) reference, except that it can be bound to a temporary value (normally, a temporary can only be bound to a const reference): void FunctionWithLValueRef(int& a) {...} void FunctionWithRValueRef(in...

Why do some c++ compilers let you take the address of a literal?

A C++ compiler that I will not name lets you take the address of a literal, int *p = Clearly 42 is an r-value and most compilers refuse to do so. Why would a compiler allow this? What could you do with this other than shoot yourself in the foot? ...

Binding temporary to a lvalue reference

I have the following code string three() { return "three"; } void mutate(string& ref) { } int main() { mutate(three()); return 0; } You can see I am passing three() to mutate method. This code compiles well. My understanding is, temporaries can't be assigned to non-const references. If yes, how this program is compiling...

"l-value required" error

When do we get "l-value required" error...while compiling C++ program???(i am using VC++ ) ...

where is rvalue stored in c?

in C, i have this code piece: int a; a = 10 + 5 - 3 I want to ask: where is (10+5-3) stored at? (As far as I know, a is located on stack, how about (10+5-3)? How does this rvalue get calculated?) ...

lvalue and rvalue

Just wonder if a literal string is a lvalue or a rvalue. Are other literals (like for int, float, char etc) lvalue or rvalue? Is the return value of a function a lvalue or rvalue? How do you tell the difference? ...

Are all temporaries rvalues in C++?

I have been coding in C++ for the last 6 years. But there is one question that I have not been able to figure out. I want to ask, are all temporaries in C++, rvalues? If no, can anyone provide me an example where temporary produced in the code is an lvalue? ...

non-class rvalues always have cv-unqualified types

§3.10 section 9 says "non-class rvalues always have cv-unqualified types". That made me wonder... int foo() { return 5; } const int bar() { return 5; } void pass_int(int&& i) { std::cout << "rvalue\n"; } void pass_int(const int&& i) { std::cout << "const rvalue\n"; } int main() { pass_int(foo()); // prints "rvalu...

Is a member of an rvalue structure an rvalue or lvalue?

A function call returning a structure is an rvalue expression, but what about its members? This piece of code works well with my g++ compiler, but gcc gives a error saying "lvalue required as left operand of assignment": struct A { int v; }; struct A fun() { struct A tmp; return tmp; } int main() { fun().v = 1; } gcc...

taking the address of a temporary object

§5.3.1 Unary operators, Section 3 The result of the unary & operator is a pointer to its operand. The operand shall be an lvalue or a qualified-id. What exactly does "shall be" mean in this context? Does it mean it's an error to take the address of a temporary? I was just wondering, because g++ only gives me a warning, whereas come...

PODs, non-PODs, rvalue and lvalues

Could anyone explain the details in terms of rvalues, lvalues, PODs, and non-PODs the reason why the first expression marked below is not ok while the second expression marked below is ok? In my understanding both int() and A() should be rvalues, no? struct A {}; int main() { int i; A a; int() = i; //Not OK (error). A() = a;...

Reference initialization in C++

Hi, Can anybody explain to me why there is a difference between these two statements? class A{}; const A& a = A(); // correct A& b = A(); // wrong It says invalid initialization of non-const reference of type A& from a temporary of type A Why does const matter here? ...

Overload on reference, versus sole pass-by-value + std::move?

It seems the main advice concerning C++0x's rvalues is to add move constructors and move operators to your classes, until compilers default-implement them. But waiting is a losing strategy if you use VC10, because automatic generation probably won't be here until VC10 SP1, or in worst case, VC11. Likely, the wait for this will be measur...

Why is T() = T() allowed?

I believe the expression T() creates an rvalue (by the Standard). However, the following code compiles (at least on gcc4.0): class T {}; int main() { T() = T(); } I know technically this is possible because member functions can be invoked on temporaries and the above is just invoking the operator= on the rvalue temporary created...

C++ rvalue temporaries in template

hello. Can you please explain me the difference between mechanism of the following: int function(); template<class T> void function2(T&); void main() { function2(function()); // compiler error, instantiated as int & const int& v = function(); function2(v); // okay, instantiated as const int& } is my reasoning correct w...

rvalues and temporary objects in the FCD

It took me quite some time to understand the difference between an rvalue and a temporary object. But now the final committee draft states on page 75: An rvalue [...] is an xvalue, a temporary object or subobject thereof, or a value that is not associated with an object. I can't believe my eyes. This must be an error, right? To ...

Rvalues in C++03

How can you tell whether or not a given parameter is an rvalue in C++03? I'm writing some very generic code and am in need of taking a reference if possible, or constructing a new object otherwise. Can I overload to take by-value as well as by-reference and have the rvalue returns call the by-value function? Or do I have a very sickenin...

C++ rvalue expression with destructor generates warning C4701 in Visual Studio 2010

The following C++ code, compiles without warning in Visual Studio 2010: extern void callFunc( int, int ); struct str_wrapper { str_wrapper(); }; extern bool tryParseInt( const str_wrapper void test() { int x, y; if ( tryParseInt( str_wrapper(), x ) } } However if str_wrapper has a user-defined destructor, the code generates t...