move-semantics Questions

2

Solved

There're plenty of articles discussing value semantics vs reference semantics, and maybe more trying to explain move semantics. However, No one has ever talked about the connection between value se...
Rosemonde asked 6/5, 2018 at 11:7

1

Solved

I'm currently learning C++ on my own, and I am curious about how push_back() and emplace_back() work under the hood. I've always assumed that emplace_back() is faster when you are trying to constru...
Oxyacetylene asked 5/6, 2018 at 17:13

1

Solved

I was binding some return value of a function to a const lvalue reference, but the object was deleted, before the lifetime of the const lvalue reference ended. In the following example the Foo obj...
What asked 4/7, 2018 at 12:53

1

Solved

I have seen the related questions and they mostly talk about if we should have const rvalue references as a parameter or not. But I still fail to reason why a non-const move constructor is being ca...
Godfather asked 27/6, 2018 at 16:13

2

Solved

I was hoping stringstream has a constructor that steals its initial content from a string&&. Do such inter-species "move constructors" generally not exist in the STL? If not, why not?
Private asked 25/6, 2018 at 0:19

1

Solved

C++11 introduced new value categories, one of them is xvalue. It is explained by Stroustrup as something like (im category): "it is a value, which has identity, but can be moved from". Another so...
Hippel asked 10/6, 2018 at 12:9

2

Solved

Say I have something like this extern "C" void make_foo (char** tgt) { *tgt = (char*) malloc(4*sizeof(char)); strncpy(*tgt, "foo", 4); } int main() { char* foo; make_foo(&foo); std::stri...
Vacuva asked 3/6, 2018 at 12:23

2

Solved

I was investigating the performance of moving std::string. For the longest time, I've regarded string moves as almost free, thinking the compiler will inline everything and it will only involve a f...
Jodiejodo asked 29/5, 2018 at 14:24

4

Solved

After using std::move in a variable that might be a field in a class like: class A { public: vector<string>&& stealVector() { return std::move(myVector); } void recreateMyVector...
Talesman asked 31/12, 2013 at 1:13

1

Solved

It seems that both order of function argument evaluation, as well as the order of lambda capture initializers, is unspecified by the C++ standard. (See http://en.cppreference.com/w/cpp/language/la...
Radiometer asked 25/5, 2018 at 21:18

4

Solved

I was trying to understand what the rule of zero says by reading this blog. IMO, it says if you declare your own destructor then don't forget to make the move constructor and move assignment as def...
Mastigophoran asked 26/11, 2015 at 7:29

2

Solved

I have come across this in some code (details eliminated for clarity): std::vector<std::vector<int>> foo; { std::vector<int> bar = {42}; foo.push_back(std::move(bar)); // Hmmm....
Moultrie asked 8/5, 2018 at 6:26

1

Solved

I have a function that potentially moves a generic argument but through their members. What of these options is more correct: This seems the more natural but it is strange because the argument is...

4

Solved

We have a bunch of value returning functions: Foo function_1(){ Foo f; // ... return f; } Bar function_2(){ Bar b; // ... return b; } Baz function_3(){ Baz b; // ... return b; } I'm ...
Griefstricken asked 30/4, 2018 at 19:22

1

From the Rust book's chapter on ownership, non-copyable values can be passed to functions by either transferring ownership or by using a mutable or immutable reference. When you transfer ownership ...
Pterodactyl asked 25/4, 2018 at 17:9

2

Solved

Trying the make simple piece of code work: std::thread threadFoo; std::thread&& threadBar = std::thread(threadFunction); threadFoo = threadBar; // thread& operator=( thread&&...
Gerlachovka asked 16/7, 2013 at 10:28

1

Solved

I have the following test code: #include <iostream> #include <string> void printValue(std::string&& val) { std::cout << "Got value: " << val << "\n"; } in...
Ferrand asked 16/4, 2018 at 1:50

2

In C++, copy-swap idiom is typically implemented like this: C& operator=(C rhs) { swap(*this, rhs); return *this; } Now, if I want to add a move-assignment operator, it is supposed to look...
Bunko asked 12/4, 2018 at 12:13

1

Solved

Consider the following program: #include <iostream> #include <utility> class T { public: T() { printf("address at construction: %zx\n", (uintptr_t)this); } // T(const T&) { prin...

1

Solved

I'm in the process of writing a basic class template. It takes two argument types for its parameters. The idea of the class is to take one type in as a const ref and the other as a ref. The functio...
Deirdra asked 26/1, 2018 at 1:27

2

There is a special description for move constructors and move assignment operators in the C++ Standard Library that says that the object the data is moved from is left in a valid but unspecified st...
Haleigh asked 26/2, 2018 at 14:2

1

Solved

There are quite complex (for me) rules that define when implicitly defaulted move constructor is generated and when it is not generated. What I'm afraid of is that the default move constructor won'...
Pindling asked 27/2, 2018 at 7:25

4

Solved

Is this struct Example { string a, b; Example(Example&& mE) : a{move(mE.a)}, b{move(mE.b)} { } Example& operator=(Example&& mE) { a = move(mE.a); b = move(mE.b); return *t...
Latecomer asked 17/8, 2013 at 15:41

1

Solved

My understanding is that in C++17, the following snippet is intended to Do The Right Thing: struct Instrument; // instrumented (non-trivial) move and copy operations struct Base { Instrument i; }...
Wholesale asked 11/2, 2018 at 2:47

3

Solved

I'm looking at some code, and I see the following function: template <typename... Args> static return_t make_return(Args &&... args) { // using std::forward<Args> will preser...
Corvese asked 6/2, 2018 at 19:32

© 2022 - 2024 — McMap. All rights reserved.