rvalue-reference Questions
4
Solved
I've been looking into some of the new features of C++11 and one I've noticed is the double ampersand in declaring variables, like T&& var.
For a start, what is this beast called? I wish G...
Devaughn asked 30/3, 2011 at 3:29
2
Solved
I have this C++ test code snippet,
#include <vector>
class A {
std::vector<int> x;
public:
A(std::vector<int>&& _x) : x(_x) {}
};
class B {
A a;
public:
B(st...
Patriliny asked 31/10, 2016 at 20:24
2
Solved
I want to make clear that the constructor of my class A will take ownership of the passed Data parameter. The obvious thing to do is take a unique_ptr by value:
class A
{
public:
A(std::unique_pt...
Humpback asked 27/9, 2016 at 9:57
1
Solved
Is there any advantage to using an r value reference when you create an object, that would otherwise be in a normal local variable?
Foo&& cn = Foo();
cn.m_flag = 1;
bar.m_foo = std::move(c...
Superstition asked 7/9, 2016 at 12:38
4
Solved
Is it possible to write a function move_and_clear such that,
for any STL container:
do_something_with(move_and_clear(container));
is equivalent to:
do_something_with(std::move(container));
cont...
Exhortative asked 24/6, 2016 at 11:19
1
Solved
Ok I have this code:
struct Mine{
template<typename T>
Mine(T&& x){
}
};
void nFoo(int&& x){
}
void sFoo(Mine x){
}
The nFoo takes an int&& directly, while the s...
Fulminous asked 18/6, 2016 at 0:11
2
Solved
is it possible to discern between these two methods?
should one not mutate an rvalue when in this case seems perfectly reusable?
TYPE a;
TYPE b = -a; // unary operator- of a TYPE& aka lvalue r...
Schilt asked 9/6, 2016 at 23:33
1
Solved
Are there any cases in which it does make sense to use const&& in range-for loops?
for (const auto && x : c) // ?
Rooted asked 4/5, 2016 at 22:34
4
Solved
I am coding some templated classes for a machine learning library, and I'm facing this issue a lot of times. I'm using mostly the policy pattern, where classes receive as template argument policies...
Pipit asked 26/4, 2016 at 14:49
2
Solved
I'm trying to come up a simple example for an operation that results in a rvalue.
This test case should have worked, but surprisingly (to me), the result of adding two ints is not an rvalue (refer...
Pepita asked 21/4, 2016 at 7:36
2
Solved
According to this document:
http://www.stroustrup.com/terminology.pdf
l-values have identity and are not movable.
pr-values are movable but don't have identity.
x-values have identity and are mo...
Nikaniki asked 15/3, 2014 at 23:20
2
Solved
In the following scenario
template <class T>
? f(T&& a, T&& b)
{
return a > b ? a : b;
}
what would the optimum return type be ? My thoughts so far are :
Return by ...
Suffice asked 17/3, 2016 at 7:2
2
Solved
The idea of move semantics is that you can grab everything from another temporary object (referenced by an rvalue reference) and store that "everything" in your object. That helps to avoid deep cop...
Wound asked 26/2, 2016 at 13:26
2
Solved
Is it possible to 'move' an rvalue into a shared_ptr. All the methods which I've tried so far result in a copy.
My desired usage pattern is:
class Element {
public:
Element(const string &);
...
Fib asked 24/2, 2016 at 13:23
3
Solved
Updating the question Why this two rvalue references examples have different behavior?:
Source code:
int a = 0;
auto && b = a++;
++a;
cout << a << b << endl;
prints 20...
Lenhart asked 10/2, 2016 at 12:52
3
Solved
First example
int a = 0;
auto && b = ++a;
++a;
cout << a << b << endl;
prints 22
Second example
int a = 0;
auto && b = a++;
++a;
cout << a << b &l...
Victory asked 10/2, 2016 at 12:35
5
Solved
A problem of "value types" with external resources (like std::vector<T> or std::string) is that copying them tends to be quite expensive, and copies are created implicitly in various contexts...
Astroid asked 16/11, 2010 at 23:45
1
I wonder which parts of the standard specify that in the following code segment:
#include <memory>
class A { };
class B : public A { };
int main()
{
std::unique_ptr<B> bptr = std::...
Austenite asked 22/1, 2016 at 16:15
2
Solved
Let's consider the following piece of code:
class Widget{
};
int main(){
Widget w;
auto lambda = bind([](Widget&& ref){ return; }, std::move(w));
return 0;
}
and it triggers error
no...
Reductase asked 19/1, 2016 at 13:10
4
Solved
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);
}
Suppose ...
Rosa asked 22/9, 2012 at 20:35
2
Solved
Thinking about (x|r|l|pr|gl)values, the following question came to my mind:
Consider the following two variable declarations:
X x = ...;
and
X&& x = ...;
and assume the ... do not de...
Coverup asked 27/12, 2015 at 10:24
2
Trying to learn lvalues, rvalues and memory allocation for them. So with a lot of learning materials there is a bit of chaos.
An rvalue is a value that needs to exist only in bounds of a expressio...
Bearcat asked 11/12, 2015 at 10:27
4
Solved
For example, stdlibc++ has the following:
unique_lock& operator=(unique_lock&& __u)
{
if(_M_owns)
unlock();
unique_lock(std::move(__u)).swap(*this);
__u._M_device = 0;
__u._M_owns...
Cashmere asked 14/7, 2011 at 1:3
1
Solved
I just noticed that I can not debug rvalue references with gdb-7.7.1 properly.
void simple(int &&i) {}
When I enter this minimalistic function I can not obtain any meaningful informatio...
Sheeran asked 7/11, 2015 at 18:9
2
Solved
Please pardon my lack of clarity on this topic. I am trying to create functions for inserting a big class into a vector. In this example, I use vector of ints as the big class.
#include <vector...
Photomicroscope asked 5/11, 2015 at 5:33
© 2022 - 2024 — McMap. All rights reserved.