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?

Viewed 1650

When create shared_ptr using a separated allocation, an explicit delete function must be provided in C++14 ctor and reset member function.

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!

By supporting shared_ptr of array feature in C++17, would those be no longer required in both ctor and 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?
1 Answers
Related