尽管如此,人们可以通过提升获得好处。
#include "boost/smart_ptr/make_shared_array.hpp"
auto int_arr_ptr = boost::make_shared<int[]>(100);
我想知道为什么C ++ 17标准不提供std::make_shared<T[]>
而它提供shared_ptr::operator[]
?
std::shared_ptr::operator[]
http://en.cppreference.com/w/cpp/memory/shared_ptr/operator_at
std::make_shared
http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared
对于数组,
- 支持此功能
std::shared_ptr
支持数组类型(从C ++ 17开始),但std::make_shared
没有。boost::make_shared
allocate_shared
和make_shared
http://www.boost.org/doc/libs/release/libs/smart_ptr/make_shared_array.html