boost :: scoped_ptr的和std ::的unique_ptr的区别 是之间的唯一不同boost::scoped_ptr<T>和std::unique_ptr<T>的事实std::uni
2017-09-14 17:34
435 查看
boost :: scoped_ptr的和std ::的unique_ptr的区别
是之间的唯一不同boost::scoped_ptr<T>和
std::unique_ptr<T>的事实
std::unique_ptr<T>有移动的语义,而
boost::scoped_ptr<T>只是一个GET
/重置智能指针?
--------------解决方案-------------
A 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.
A 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_ptrlying 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_ptr | const std::unique_ptr | |
Copyable | No | No |
Movable | No | Yes |
with scoped_ptr
If you want to disallow moving with
std::unique_ptr, use
const std::unique_ptr.
boost::scoped_ptr | const std::unique_ptr | |
Copyable | No | No |
Movable | No | No |
相关文章推荐
- boost :: scoped_ptr的和std ::的unique_ptr的区别
- boost::scoped_ptr<CUser> apUser(new CUser);
- std::unique_lock<std::mutex> or std::lock_guard<std::mutex> C++11 区别
- 详解 boost 库智能指针(scoped_ptr<T> 、shared_ptr<T> 、weak_ptr<T> 源码分析)
- <Effective Modern C++>Item 18: Use std::unique_ptr for exclusive-ownership resource management.
- 从零开始学C++之boost库(一):详解 boost 库智能指针(scoped_ptr<T> 、shared_ptr<T> 、weak_ptr<T> 源码分析)
- [置顶] 从零开始学C++之boost库(一):详解 boost 库智能指针(scoped_ptr<T> 、shared_ptr<T> 、weak_ptr<T> 源码分析)
- [置顶] 从零开始学C++之boost库(一):详解 boost 库智能指针(scoped_ptr<T> 、shared_ptr<T> 、weak_ptr<T> 源码分析)
- Boost源码剖析--<boost/smart_ptr/scoped_ptr.hpp>
- mongodb 中 scoped_ptr.hpp:99: T* boost::scoped_ptr<T>::operator->() const [with T = mongo::AtomicWord
- 详解 boost 库智能指针(scoped_ptr<T> 、shared_ptr<T> 、weak_ptr<T> 源码分析)
- C/C++: std::auto_ptr 与 boost:: scoped_ptr 区别
- 利用std::shared_ptr<void> 回收不同类型对象的内存
- std::shared_ptr<void>的工作原理
- jquery在<div>之间新增内容---html()和append()及after()区别
- <jsp:include page=”XXX”>与<%@ include file=”XXX”%>之间有什么区别
- 转载只为记录经典之<Telnet、SSH(SSH1和SSH2)之间的区别 >
- boost综合使用<function,bind,thread,mutex,condition_variable,shared_ptr>
- 回调函数 typedef bool (*IsUsed)(const string &name,boost::shared_ptr<ShpGeometry> oneGeometry);
- Caffe错误boost::python::register_ptr_to_python<boost::shared_ptr<Blob<Dtype> > >();