Can modern C++ get you performance for free?

It is sometimes claimed that C++11/14 can get you a performance boost even when merely compiling C++98 code. The justification is usually along the lines of move semantics, as in some cases the rvalue constructors are automatically generated or now part of the STL. Now I’m wondering whether these cases were previously actually already handled … Read more

C++11 rvalues and move semantics confusion (return statement)

I’m trying to understand rvalue references and move semantics of C++11. What is the difference between these examples, and which of them is going to do no vector copy? First example std::vector<int> return_vector(void) { std::vector<int> tmp {1,2,3,4,5}; return tmp; } std::vector<int> &&rval_ref = return_vector(); Second example std::vector<int>&& return_vector(void) { std::vector<int> tmp {1,2,3,4,5}; return std::move(tmp); } … Read more

push_back vs emplace_back

I’m a bit confused regarding the difference between push_back and emplace_back. void emplace_back(Type&& _Val); void push_back(const Type& _Val); void push_back(Type&& _Val); As there is a push_back overload taking a rvalue reference I don’t quite see what the purpose of emplace_back becomes? 7 s 7 In addition to what visitor said : The function void emplace_back(Type&& … Read more