make_unique and perfect forwarding

Why is there no std::make_unique function template in the standard C++11 library? I find std::unique_ptr<SomeUserDefinedType> p(new SomeUserDefinedType(1, 2, 3)); a bit verbose. Wouldn’t the following be much nicer? auto p = std::make_unique<SomeUserDefinedType>(1, 2, 3); This hides the new nicely and only mentions the type once. Anyway, here is my attempt at an implementation of make_unique: … Read more

What are the main purposes of using std::forward and which problems it solves?

In perfect forwarding, std::forward is used to convert the named rvalue references t1 and t2 to unnamed rvalue references. What is the purpose of doing that? How would that affect the called function inner if we leave t1 & t2 as lvalues? template <typename T1, typename T2> void outer(T1&& t1, T2&& t2) { inner(std::forward<T1>(t1), std::forward<T2>(t2)); … Read more

What does T&& (double ampersand) mean in C++11?

I’ve been looking into some of the new features of C++11 and one I’ve noticed is the double ampersand in declaring variables, like T&& var. For a start, what is this beast called? I wish Google would allow us to search for punctuation like this. What exactly does it mean? At first glance, it appears … Read more