rvalue-reference Questions
4
Solved
I am writing library which wraps a lot of functions and methods from other library. To avoid coping of return values I am applying std::forward like so:
template<class T>
T&& wrapper...
Portwin asked 18/10, 2012 at 6:4
5
Solved
I posted this answer: https://stackoverflow.com/a/28459180/2642059 Which contains the following code:
void foo(string&& bar){
string* temp = &bar;
cout << *temp << " @:"...
Emmy asked 12/2, 2015 at 16:54
8
In perfect forwarding, std::forward is used to convert the named rvalue references t1 and t2 to unnamed rvalue references. What is the purpose of doing that? How would that affect the called functi...
Underglaze asked 27/8, 2010 at 6:59
3
Solved
Today I ran into roughly the following code:
#include <iostream>
void f(float&& f) { std::cout << f << "f "; }
void f(int&& i) { std::cout <<...
Mayman asked 8/11, 2023 at 12:8
2
Solved
I've got a question of similiar nature like this one posted 5 years ago:
Why are rvalues references variables not rvalue?
My major concern is why can I do this:
int&& k = 3;
k++;
but I can...
Iotacism asked 27/9, 2020 at 13:25
2
I think I understand functions with signatures like:
void f(std::string&&):
It will be applied to rvalues to reuse their resources. However, I've seen occasionally code like:
std::string t...
Overmaster asked 30/6, 2023 at 18:10
1
Solved
I'm encountering an unexpected behavior in my code when calling overloaded functions with different rvalue reference types. The code snippet below demonstrates the issue:
#include <iostream>
...
Rensselaerite asked 30/6, 2023 at 2:23
7
Solved
How do I capture by move (also known as rvalue reference) in a C++11 lambda?
I am trying to write something like this:
std::unique_ptr<int> myPointer(new int);
std::function<void(void)&...
Voncile asked 27/12, 2011 at 1:28
1
The following code:
#include <iostream>
struct A {
A() { std::cout << "()" << std::endl; }
A(A&&) { std::cout << "(A&&)" <&...
Conchaconchie asked 8/5, 2023 at 10:32
2
Solved
Why rvalue reference template variable b<int> is able to bind to lvalue a?
#include <iostream>
int a = 3;
template<typename T>
T&& b = a;
int main() {
if(std::is_same_...
Maryjanemaryjo asked 3/5, 2023 at 12:56
2
Solved
I wanted to know how this is possible ?
template<typename T>
void Test(T&& arg)
{
arg = 14;
}
int a = 23;
Test(a);
My question is that the function Test requires an argument of ...
Gaiety asked 11/5, 2014 at 22:35
8
Solved
I guess not, but I would like to confirm. Is there any use for const Foo&&, where Foo is a class type?
Geordie asked 8/2, 2011 at 21:49
2
Solved
#include <sstream>
#include <string>
using namespace std;
template<typename T>
string ToString(const T& obj)
{
ostringstream oss;
oss << obj;
//
// oss will never...
Leguminous asked 8/12, 2016 at 8:50
2
Solved
The following code:
#include <tuple>
int main ()
{
auto f = [] () -> decltype (auto)
{
return std::get<0> (std::make_tuple (0));
};
return f ();
}
(Silently) generates code...
Ecg asked 20/12, 2017 at 11:45
0
#include <functional>
#include <iostream>
#include <string>
#include <utility>
using namespace std;
template<typename Func, typename... Args>
void do_task(Func ...
Pernambuco asked 22/8, 2022 at 16:1
4
Solved
If we want to initialize an reference with an different type, we need to make it const (const type*) so that an temporary can be generated implicit and the reference binded to with. Alternativaly, ...
Duckling asked 17/7, 2022 at 20:29
3
Why it is not possible to convert rvalues to lvalues? It is possible to do a conversion in the opposite direction though. Technically rvalues do have a memory address, isn't it?
Moccasin asked 21/6, 2017 at 13:39
1
Solved
I'm wondering what's the difference between for (auto& i : v) and for (auto&& i : v) in a range-based for loop like in this code:
#include <iostream>
#include <vector>
int...
Klug asked 28/3, 2015 at 17:54
3
Solved
In Scott Meyer's new book, he proposes an example usage for rvalue reference qualifiers that looks something like this:
class Widget {
private:
DataType values;
public:
DataType& data() &am...
Hilleary asked 8/12, 2014 at 22:33
2
Solved
I am trying to get the grasp of rvalue references and move semantics with a simple self-made example but I can't understand a specific part. I have created the following class:
class A {
public:
A...
Flowerer asked 15/12, 2021 at 13:59
6
Solved
Let's take the following method as an example:
void Asset::Load( const std::string& path )
{
// complicated method....
}
General use of this method would be as follows:
Asset exampleAsset;...
Gardenia asked 28/3, 2013 at 3:43
3
Solved
Consider this class with three constructors:
class Circle {
public:
Circle(int r) {
_radius = r;
}
Circle(const Circle& c){
_radius = c.radius();
cout << endl << "Copy const...
Beefeater asked 29/4, 2012 at 17:25
9
Solved
So, after watching this wonderful lecture on rvalue references, I thought that every class would benefit of such a "move constructor", template<class T> MyClass(T&& other) edit ...
Allyn asked 24/1, 2011 at 13:51
2
Solved
Mostly all things explained by fredoverflow(user 237K Rep.) in his Two answers
https://mcmap.net/q/15702/-what-is-move-semantics
https://mcmap.net/q/15702/-what-is-move-semantics
But while implem...
Yolandayolande asked 31/5, 2021 at 10:46
3
Solved
I understand that a forwarding reference is "an rvalue reference to a cv-unqualified template parameter", such as in
template <class T> void foo(T&& );
which means the abov...
Carmine asked 1/9, 2017 at 8:33
1 Next >
© 2022 - 2024 — McMap. All rights reserved.