With the new standard coming (and parts already available in some compilers), the new type std::unique_ptr is supposed to be a replacement for std::auto_ptr. Does their usage exactly overlap...
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...
I’m using the pimpl-idiom with std::unique_ptr: class window { window(const rectangle& rect); private: class window_impl; // defined elsewhere std::unique_ptr<window_impl> impl_; // won't compile }; However, I get a compile...
What is wrong with this program? #include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>> vec; int x(1); std::unique_ptr<int> ptr2x(&x); vec.push_back(ptr2x); //This tiny command has a vicious error. return 0;...
I have some code in a header that looks like this: #include <memory> class Thing; class MyClass { std::unique_ptr< Thing > my_thing; }; If I include this header in...
std::unique_ptr has support for arrays, for instance: std::unique_ptr<int> p(new int...
This question already has answers here: Closed 10 years ago. Possible Duplicates: pimpl: shared_ptr or unique_ptr smart pointers (boost) explained Could someone explain differences between shared_ptr and unique_ptr? 4...
unique_ptr<T> does not allow copy construction, instead it supports move semantics. Yet, I can return a unique_ptr<T> from a function and assign the returned value to a variable. #include...
I’m new to move semantics in C++11 and I don’t know very well how to handle unique_ptr parameters in constructors or functions. Consider this class referencing itself: #include <memory>...