push_back vs emplace_back

In addition to what visitor said : The function void emplace_back(Type&& _Val) provided by MSCV10 is non conforming and redundant, because as you noted it is strictly equivalent to push_back(Type&& _Val). But the real C++0x form of emplace_back is really useful: void emplace_back(Args&&…); Instead of taking a value_type it takes a variadic list of arguments, so that means that you can now perfectly … Read more

What is std::move(), and when should it be used?

Wikipedia Page on C++11 R-value references and move constructors In C++11, in addition to copy constructors, objects can have move constructors.(And in addition to copy assignment operators, they have move assignment operators.) The move constructor is used instead of the copy constructor, if the object has type “rvalue-reference” (Type &&). std::move() is a cast that produces … Read more

What is move semantics?

I find it easiest to understand move semantics with example code. Let’s start with a very simple string class which only holds a pointer to a heap-allocated block of memory: Since we chose to manage the memory ourselves, we need to follow the rule of three. I am going to defer writing the assignment operator and … Read more

push_back vs emplace_back

In addition to what visitor said : The function void emplace_back(Type&& _Val) provided by MSCV10 is non conforming and redundant, because as you noted it is strictly equivalent to push_back(Type&& _Val). But the real C++0x form of emplace_back is really useful: void emplace_back(Args&&…); Instead of taking a value_type it takes a variadic list of arguments, so that means that you can now perfectly … Read more