P
puzzlecracker
I am sure all remember the infamous 'swap trick' to actually clear the
content of a vector.
void somefunc(){
vector<SomeType>(st).swap(st);
}
Here we create a temprary variable that is populated with st elements
and do the swap...
My question is at which point will that temp variable be destroyed: at
the end of the function or the statement?
If it happens at the end of the function, then the swap trick for the
actual removal of >= n/2 elements is an exercise in futility, for total
storage won't ebb, but may increase!
Any thoughts?
content of a vector.
void somefunc(){
vector<SomeType>(st).swap(st);
}
Here we create a temprary variable that is populated with st elements
and do the swap...
My question is at which point will that temp variable be destroyed: at
the end of the function or the statement?
If it happens at the end of the function, then the swap trick for the
actual removal of >= n/2 elements is an exercise in futility, for total
storage won't ebb, but may increase!
Any thoughts?