简体   繁体   中英

Changing boost::scoped_ptr to std::unique_ptr

I am using boost::scoped_ptr in the code which I would like to replace with std::unique_ptr . I would like to know if there are any disadvantages in moving to std::unique_ptr . Boost is portable across platforms and compilers. But I am not sure if C++11 supported by all compilers such as MSVC. I know GCC and Clang support C++11 pretty well.

I've already read the SO question “ intrusive_ptr in C++11 ” whose short answer is “No”. So If anyone had experience in using both, please share your comments and thoughts

Mgetz has generously provided the information that all recent VS implementations supply unique_ptr .

I recommend that you replace boost::scoped_ptr<T> with const std::unique_ptr<T> . The reason for the const is that this most closely models boost::scoped_ptr<T> which is not "movable." However I believe boost::scoped_ptr<T> does support swapping. So if you are using that, the compiler will complain everywhere you try to swap a const std::unique_ptr<T> and you can then mark those instances as non- const .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM