由于 C++17 支持数组的 shared_ptr,这是否意味着在 ctor 和 reset 中不再需要 T[] 的显式删除器?

Since C++17 supports shared_ptr of array, does this mean that an explicit deleter for T[] is no longer required in both ctor and reset?

当使用分离分配创建 shared_ptr 时,C++14 构造函数和重置成员函数中必须提供显式删除函数。

using std::string;
using std::shared_ptr;
using std::default_delete;
int arr_size{};
...


auto string_arr_sptr_cpp14 = 
         shared_ptr<string[]>(new string[arr_size], default_delete<string[]>() );
string_arr_sptr_cpp14.reset(new string[arr_size], default_delete<string[]>() );
// define an explicit deleter, 
// or otherwise, "delete ptr;" will internally be used incorrectly!

通过支持 C++17 中的 shared_ptr 数组功能,是否不再需要 ctor 和 reset 中的数组功能?

auto string_arr_sptr_cpp17 = shared_ptr<string[]>(new string[arr_size]);
string_arr_sptr_cpp14.reset(new string[arr_size]);
// deduced delete function calls "delete[] ptr;" correctly now?

你是对的,shared_ptr<T[]> 现在可以自然地正确处理调用 delete[]

http://eel.is/c++draft/util.smartptr.shared#const-5

Effects: When T is not an array type, constructs a shared_­ptr object that owns the pointer p. Otherwise, constructs a shared_­ptr that owns p and a deleter of an unspecified type that calls delete[] p.

reset() 而言:

http://eel.is/c++draft/util.smartptr.shared#mod-3

Equivalent to shared_­ptr(p).swap(*this).

这将传输规范要求的自定义删除器。