boost :: scoped_ptr的和std ::的unique_ptr的区别 是之间的唯一不同boost::scoped_ptr<T>和std::unique_ptr<T>的事实std::uni

boost :: scoped_ptr的和std ::的unique_ptr的区别

是之间的唯一不同boost::scoped_ptr<T>std::unique_ptr<T>的事实std::unique_ptr<T>有移动的语义,而boost::scoped_ptr<T>只是一个GET /重置智能指针?

--------------解决方案-------------

unique_ptr is also known as std::unique_ptr. Before C++11 it was boost::unique_ptr, but became a part of STD library in C++11 and is now called std::unique_ptr.

scoped_ptr is generally known as boost::scoped_ptr, and is from the “ancient” ages before C++11 came along with the <memory> header with std::unique_ptr (and std::shared_ptr). Note that there is NO such thing as std::scoped_ptr! Only boost::scoped_ptr and std::unique_ptr. Generally, its std::unique_ptr you should use.

If you’ve been using boost, and have any scoped_ptr lying around, you can (almost always) safely replace them with std::unique_ptr. There are a few subtle differences between scoped_ptr and unique_ptr, but they are mostly an artifact on how “old” they are.

 boost::scoped_ptrconst std::unique_ptr
CopyableNoNo
 Movable No Yes

Related: Memory leak with scoped_ptr

If you want to disallow moving with std::unique_ptr, use const std::unique_ptr.

 boost::scoped_ptrconst std::unique_ptr
CopyableNoNo
 Movable No No


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值