The simplest answer is NO, the memory cannot be re-used.
To explain a little - the internal node class of std::list
does not keep the "pointer" to value - but value itself. This node is defined more or less like this:
template <class T>
struct List_Node {
T value;
List_Node* prev;
List_Node* next;
};
So there is no possibility to "re-use" allocated memory.
But - nodes can be transferred between std::list<T>
objects with splice, thus we can avoid reallocation.
std::list<St> st{{1,2}};
std::list<St> St_list;
St_list.splice(St_list.end(), st);
// now st is empty, St{1,2} is in St_list - no "reallocation" happened
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…