Linked Questions

229 votes
4 answers
146k views

I don't understand when I should use std::move and when I should let the compiler optimize... for example: using SerialBuffer = vector< unsigned char >; // let compiler optimize it ...
Elvis Dukaj's user avatar
  • 7,428
33 votes
4 answers
15k views

Tonight I've been taking a look at some code I've been working on over the last few days, and began reading up on move semantics, specifically std::move. I have a few questions to ask you pros to ...
Moo-Juice's user avatar
  • 38.9k
25 votes
3 answers
36k views

Possible Duplicate: C++11 rvalues and move semantics confusion What I think is correct is std::string GetLine() { std::string str; std::getline(std::cin, str); return std::move(str); } ...
EddieV223's user avatar
  • 5,373
35 votes
3 answers
25k views

I have a very basic question: is it a good idea to return a std::vector<A> using std::move? For, example: class A {}; std::vector<A> && func() { std::vector<A> v; /* ...
Koban's user avatar
  • 523
12 votes
1 answer
21k views

I have a function struct foo { std::vector<int> v; }; foo func(); will the vector inside foo be moved or copied when returning from the function?
yngccc's user avatar
  • 5,704
8 votes
1 answer
713 views

I have TTempTable class with move symantics. I wrote TTempTable&& MyFunction() { TTempTable tmp = f(...); ... return std::move(tmp); } and got no compiler errors. Was this correct?
Dims's user avatar
  • 51.8k
4 votes
3 answers
229 views

I'm confused as to what is going on in the following code snippet. Is move really necessary here? What would be the most optimal + safe way of returning the temporary set? set<string> getWords()...
Victor Parmar's user avatar
2 votes
1 answer
233 views

I came across the following code snippet std::string&& test() { std::string m="Hello"; return (std::move(m)); } int main() { std::string&& m = test(); } I understand the ...
James Franco's user avatar
  • 4,786
1 vote
0 answers
117 views

which is right? std::string get_string() { std::string result; // ... more operations. return std::move(result); } Or std::string&& get_string() { std::string ...
Khurshid's user avatar
  • 2,744
0 votes
0 answers
89 views

I am trying to come to terms with r-value references. I discovered that string's operator+ is always declared to return by value. Why is operator+ defined to return by value: basic_string operator+(...
Shriram V's user avatar
  • 1,598
2 votes
1 answer
148 views

How can I trust the compiler for non-guaranteed copy elision (in case of return value optimization) in this example code: struct X { X() : size(10000), very_large_buffer(new char[size]) { } ...
Andrey Rubliov's user avatar
82 votes
11 answers
67k views

I am wondering about this because of scope issues. For example, consider the code typedef struct { int x1;/*top*/ int x2;/*bottom*/ int id; } subline_t; subline_t subline(int x1, int x2, ...
ldog's user avatar
  • 12.3k
62 votes
7 answers
42k views

I have a very basic question in C++. How to avoid copy when returning an object ? Here is an example : std::vector<unsigned int> test(const unsigned int n) { std::vector<unsigned int>...
Vincent's user avatar
  • 61.1k
54 votes
5 answers
14k views

Is RVO (Return Value Optimization) guaranteed or applicable for all objects and situations in C++ compilers (specially GCC)? If answer is "no", what are the conditions of this optimization for a ...
masoud's user avatar
  • 56.8k
37 votes
8 answers
7k views

As far as I understand one of the purposes of adding move semantics is to optimize code by calling special constructor for copying "temporary" objects. For example, in this answer we see that it can ...
UmmaGumma's user avatar
  • 5,713

15 30 50 per page
1
2 3 4 5