Quick Q: Why does this function take a parameter by value? -- StackOverflow
A classic on SO:
Why do we copy then move?
I saw code somewhere in which someone decided to copy an object and subsequently move it to a data member of a class. This left me in confusion in that I thought the whole point of moving was to avoid copying. Here is the example:
struct S { S(std::string str) : data(std::move(str)) {} };Here are my questions:
- Why aren't we taking an rvalue-reference to
str?- Won't a copy be expensive, especially given something like
std::string?- What would be the reason for the author to decide to make a copy then a move?
- When should I do this myself?

Quick: Would you resort to stringstream? But t
Some high-performance techniques that you an use for more than just parsing, including this week's darling of memory management:
When you see anyone claim performance parity between <other language> and C++, one of the first things to look for is whether the C++ version of their test code is correctly using arrays and traversing them in order. If the test code is just doing equivalent pointer-chasing in both languages, the performance comparison is largely meaningless because the program is probably memory-bound and not properly written to use C++'s default container (