The standard provides a template specialization of std::unique_ptr
which correctly calls the delete[]
from its destructor:
void func()
{
std::unique_ptr< int[] > arr(new int[10]);
.......
}
With std::shared_ptr
this specialisation is not available, so it is necessary to
to provide a deleter which correctly calls delete[]
:
void func()
{
// Usage
shared_ptr array (new double [256], [](double* arr) { delete [] arr; } );
..............
}
Is this simply an oversight? (in the same way that there is an std::copy_if
) or is there a reason?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…