mercredi 18 décembre 2019

What happens to the left hand side std::vector resources on move assignment?

I was trying to find out if it's granted by the C++ 11 standard that the resources of a std::vector receiving a move assignment are freed.

I'll give you an example:

std::vector<int> a {1, 2};
std::vector<int> b {3, 4};
a = std::move(b);

Now what I'd be expecting is that both a and b are wrapping a regular array (usually) and they have a pointer to it, namely a_ptr and b_ptr. Now I think the move assignment among other things does a_ptr = b_ptr. Does the standard guarantee that the memory in a_ptr is freed before or by this?

Aucun commentaire:

Enregistrer un commentaire