The rvalue tag has no wiki summary.
0
votes
1answer
32 views
Trying to wrap std containers to store rvalue references (like unique_ptr, but on the stack)
I'm trying to do strange things again.
Okay, here's the general idea. I want a std::list (and vector and so on) that actually own the objects they contain. I want to move the values into it, and ...
2
votes
5answers
68 views
Operator precedence and pointer arithmetic
Given the following code:
void Allocate(int *p)
{
p = new int;
*p++ = 2;
}
int main()
{
int i = 10;
Allocate(&i);
std::cout << i << std::endl;
}
I'm a bit ...
39
votes
5answers
2k views
Isn't the const modifier here unnecessary? [duplicate]
The "Effective C++" Item 3 says "Use const whenever possible", and it gives an example like:
const Rational operator*(const Rational& lhs,
const Rational& rhs);
...
0
votes
4answers
57 views
invalid initialization of non-const reference of type 'int&' from a temporary of type 'int'
#include<iostream>
using namespace std;
int fun(int &x)
{
return x;
}
int main()
{
cout << fun(10);
return 0;
}
Can anyone explain the reason of the error ?
Thanks
2
votes
0answers
40 views
C++11 for loop with rvalue reference index [duplicate]
This piece of code I came across really confuses me, it seems to make use of rvalue semantics in order to print a vector:
std::vector<int> b = {0,0,0,14,15,123,2431};
mergeAndSort(a,b);
...
7
votes
1answer
153 views
Difference between “return-by-rvalue-ref” & “return-by-value” when you return using std::move?
Considering the following code:
#include <iostream>
using namespace std;
struct I {
I(I&& rv) { cout << "I::mvcotr" << endl; }
};
struct C {
I i;
I&& ...
1
vote
1answer
51 views
Objects lifetime with move operation and rvalue forwarding
I would like to know if the following code is valid.
In particular, I'm confused about the lifetime of the objects involved here after a call to new_S.
From my understanding, T will be copied when ...
5
votes
2answers
131 views
Are member variables in temporary objects implicitly moved when possible?
In my classes I use std::vector etc. as member variables, which come with their own move constructors. I don't explicitly declare move constructors for my classes and they are not implicitly declared ...
0
votes
4answers
75 views
Using the result of compound assignment as an lvalue [duplicate]
I'm surprised that this works:
double x = 3;
double y = 2;
(x *= 2) += y;
std::cout << x << std::endl;
The result is 8, which is what it looks like the programmer is trying to achieve. ...
1
vote
1answer
22 views
When can you use a character array's name to make a valid L-value?
Given a pointer and an array, setting one equal to another fails in one case, and works in another.
char *c_ptr = "I'm a char pointer";
char c_arry[] = "I'm a char array";
c_ptr = c_arry; //This ...
5
votes
2answers
108 views
Is it valid to bind non-const lvalue-references to rvalues in C++ 11?(modified)
I know in c++03, an an non-const reference cannot be bound to rvalues.
T& t = getT(); is invalid, and in c++11, we can do this: T&& t = getT(); but what about the above code, should that ...
2
votes
4answers
97 views
How to test lvalue or rvalue in this case
The code is as following:
struct A
{
static int k;
int i;
};
int A::k = 10;
A func() { A a; return a; }
My question is, how can I tell whether func().k or func().i is an lvalue or not? If ...
0
votes
5answers
119 views
Passing r-value as non-const reference (VS warning C4239)
What I wish to do (using a C++ lambda) is effectively:
std::vector<MyType> GetTheArray () {return something;}
const auto DoSomething = [](std::vector<MyType> & array)
{
//Some ...
1
vote
2answers
33 views
bind a tempory variable to a non const reference compile on visual [duplicate]
#include<iostream>
struct Foo
{
};
void func(Foo& f)
{
std::cout << "foo" ;
}
int main()
{
func(Foo());//ok compile
std::cin.ignore();
return 1;
}
the standard ...
6
votes
2answers
144 views
Wrong forwarding of rvalue reference
I was experimenting with the newly added rvalue refernces ( in vs2012 express ).
I don't understand something tho. Given the code below ( most of it taken from the c++ standard where std::forward is ...
5
votes
3answers
187 views
C++ function returns a rvalue, but that can be assigned a new value?
The code is as follows:
#include <iostream>
using namespace std;
class A {
};
A rtByValue() {
return A();
}
void passByRef(A &aRef) {
// do nothing
}
int main() {
A ...
4
votes
1answer
151 views
Unable to overload with references to *this
Here is a busybox I wrote to play with the new feature in gcc-4.8.1+ (I think clang-2.9+ should do this too) for N2439 (ref-qualifiers for 'this'):
class Foo
{
public:
Foo(int i) : _M_i(i) { }
...
-5
votes
5answers
114 views
What is the reason of the names “lvalue” and “rvalue” in C/C++?
What is the reason of the names "lvalue" and "rvalue" in C/C++ (I know what is a lvalue or a rvalue)?
0
votes
1answer
110 views
What's this code supposed to do? (reference to rvalue)
I have read that the code below is valid in C++11:
int && a = 3;
a = 4;
Is it supposed to write 4 in the memory address where the numeric literal 3 is stored? Maybe some compiler ...
4
votes
1answer
145 views
What is an example of a difference in allowed usage or behavior between an xvalue and a prvalue FOR NON-POD objects?
What are rvalues, lvalues, xvalues, glvalues, and prvalues? gives a good overview of the taxonomy of rvalues/lvalues, and one of the recent answers to that question ...
10
votes
1answer
376 views
C++ type cast operator code that won't compile in visual studio 2012, but worked fine in visual studio 2005
I'm trying to update a old project that has been building with visual studio 2005 to uses visual studio 2012, and I'm getting an error that I cant solve.
The code that works fine under VS2005:
...
-1
votes
1answer
86 views
RValue Pointers?
How can I tell if a pointer is an RValue or I don't know what I'm talking about.. This really ridiculous idea popped into my head while drinking a beer..
What if you have stupid programmer/user..
...
7
votes
1answer
175 views
why does --list.end() compile?
list's end() returns a copy of the past-the-end iterator, right?
Therefore, list.end() is an rvalue, right?
the -- operator-function overloaded for list iterator takes a non-const reference, right?
...
8
votes
1answer
214 views
What is the value category of the operands of C++ operators when unspecified?
PREMISE:
The C++11 Standard classifies expressions into three disjoint value categories: lvalues, xvalues, and prvalues (§ 3.10/1). An explanation of what value categories are is available for ...
5
votes
3answers
229 views
Pass lvalue to rvalue
I made a small 'blocking queue' class. It irritates me that I have created redundant code for values passed into the enqueue member function.
Here are the two functions that do the same exact thing ...
3
votes
1answer
86 views
Which of these five statements about lvalues is true? [closed]
I'm doing the following puzzle. Mayby someone could check if I'm choosing the right answer.
Have a look.
Which one of the following is a true statement about an lvalue?
1 An lvalue is the result of ...
1
vote
2answers
135 views
Why element-getters from rvalued-stl-container return lvalue?
I have a code which have to deal with rvalued stl containers.
My question is: why member functions which return an element from rvalued-stl-container, like in:
vector<int>{1}.front()
...
2
votes
2answers
261 views
C++11 - Return rvalue passed into a function by lvalue?
In C++11, it is common practice to pass an lvalue into a function by reference.
int& f(int& a){
return a;
}
int main(void){
auto a = 1;
auto b = f(a);
return 0;
}
However, ...
0
votes
1answer
33 views
php include as rvalue?
I wonder if it is possible to use php include as a Rvalue, like this example:
$foo = include('bar.php);
I did a few experiments but it seems to not be possible.
The php files that I would like to ...
1
vote
3answers
94 views
C++ constructor issues
I wonder if anybody can help with what seems to me like strange behaviour in c++ (gcc latest version). Below is some code that compiles successfully where I would expect a compile time error due to ...
5
votes
2answers
356 views
On OS X, simple C++ program gives incorrect results (which are a result of command-line options 'c++03' vs 'c++11')
This simple program (when compiled on Linux) will CORRECTLY give two different answers based on whether it's compiled with -std=c++0x or not.
Problem: I cannot reproduce the same thing on OS X ...
0
votes
3answers
91 views
Returning a mutable value in C++11
I was wondering about having a method return an r-value. Specifically, I was wondering if there was a way to do this with an overloaded operator.
I have this code:
struct vec4 {
float x;
...
0
votes
2answers
99 views
How lvalue can be converted as rvalue
int x = 8;
int y = x ;
Here how a lvalue can be act as rvalue ? I know this is a silly question , but i just want to make my concepts clear on rvalue and lvalue .
0
votes
1answer
77 views
c++: function lvalue or rvalue
I just started learning about rvalue references in c++11 by reading this page, but I got stuck into the very first page. Here is the code I took from that page.
int& foo();
foo() = 42; // ...
0
votes
5answers
142 views
Return values in c++03 vs 11 [closed]
I have spend a few hours about rvalue s and lvalue. Here is what I understand
int main()
{
//.....
Foo foo = Bar1();
foo = Bar2();
//......
}
Foo Bar1()
{
//Do something including create ...
1
vote
0answers
61 views
Why is a hard-coded string constant an lvalue? [duplicate]
Possible Duplicate:
Why are string literals l-value while all other literals are r-value?
In Can someone please explain move semantics to me? appears the following code snippet and comment:
...
5
votes
3answers
120 views
Can we reliably pre-increment/decrement rvalues?
For example, std::vector<int>::iterator it = --(myVec.end());. This works in GCC 4.4 but I have heard a rumor that it's not portable.
2
votes
1answer
100 views
Returning pointer by value does not move the object
I have compiled this code with vs2011. It prints first constructor then copy constructor.
But if I change the function to return a instead of ap, it will move the object. Is this a bug or why does it ...
0
votes
0answers
51 views
Why don't most languages allow switch on rvalue?
I once worked with a language (won't say which - it's outdated and nobody is likely to have heard of it, much less used it) where you could reverse the typical arrangement of a switch statement, and ...
0
votes
0answers
16 views
rvalue assignment operator called in error?
I cannot figure out why the VS2010 compiler is calling the rvalue assignment operator here. The object it steals the value from is used again immediately in the code. Is this a bug in the compiler? ...
4
votes
1answer
107 views
rvalue reference and literal
Consider the code
template <typename... Args>
void foo (Args&& ...)
{
}
template <typename... Args>
void bar (Args&& ... args)
{
foo (std::forward (args)...);
}
int ...
3
votes
2answers
64 views
Is it legal to take the address of a const lvalue reference?
#include <iostream>
int foo()
{
return 0;
}
int main()
{
const int& a = foo();
std::cout << &a << std::endl;
}
In this code, a binds to a rvalue. Is it legal to take ...
1
vote
2answers
82 views
Is it necessary to have a temporary or a literal to have an rvalue?
This question asks if all temporaries are rvalue.
The answer is no, because if we consider this expression:
const int &ri = 2 + 3;
then, the very same temporary (2 + 3), which is an rvalue ...
10
votes
2answers
113 views
Why are tokens wrapped by parentheses not r-value expressions?
Consider the following code:
#include <iostream>
struct Foo
{
Foo() : bar( 0 ) {}
int bar;
};
int main()
{
Foo foo;
++(foo.bar);
std::cout<< foo.bar << std::endl;
...
0
votes
2answers
33 views
Convert a Vector of Strings to the Rvalue of an Assignement Statement
I cant think of an efficient way to convert a vector of strings to become the rvalue of an assignment statement. So for example, i have a vector with three elements "5", "*", "3" so what I need is an ...
1
vote
1answer
345 views
c++ unique_ptr argument passing
Suppose I have the following code:
class B { /* */ };
class A {
vector<B*> vb;
public:
void add(B* b) { vb.push_back(b); }
};
int main() {
A a;
B* b(new B());
a.add(b);
...
5
votes
3answers
119 views
rvalue definition is objects that cannot be assigned values, but why are literals lvalues?
So i'm reviewing in advanced our upcoming topics and I've come accross lvalues and rvalues, although the definition confuses me. Why is a literal an lvalue?
"rvalue refers to a data value that is ...
8
votes
2answers
159 views
Result of ternary operator not an rvalue
If you compile this program with a C++11 compiler, the vector is not moved out of the function.
#include <vector>
using namespace std;
vector<int> create(bool cond) {
...
1
vote
2answers
77 views
rvalue delegation, or the rvalue equivalent of a const member function
struct that
{
that &frob()
{
return *this;
}
that frob() const
{
return that(*this);
}
//that &&frob() && //<-called only if *this ...
7
votes
3answers
223 views
When should I choose copy elision over passing argument by const reference? [duplicate]
Possible Duplicate:
Is pass-by-value a reasonable default in C++11?
I'm reading Want Speed? Pass by Value. by Dave Abrahams about copy elision and RVO. And I'm wondering why do we need the ...