mercredi 2 mars 2016

Making std::array only call destructor on part of array

I'm using std::array to replace the 'pointer and count' calling methods in some C code I'm upgrading to C++. Creating and using the std::array is no problem, but on destruction it will call the destructor on all elements.

But my arrays are often not completely full, causing a destructor call on an empty element. Usually not a problem, as they will be constructed with the default constructor, but I'd like to just remove an element by decrementing a size count, which means leaving a 'used' element in the array, which then causes problems on destruction.

What would be the best way to make sure only a part of the array is destroyed, by having the destructor called on its elements?

Aucun commentaire:

Enregistrer un commentaire