vector decoy;
void clear_decoy() {
decoy.clear();
vector (decoy).swap(decoy);
}
In the above method
That code is a failed attempt to use a common trick to ensure the memory allocated by the vector is freed. It may or may not actually do that, depending on whether or not the vector's copy constructor allocates memory to match the other vector's size, or its capacity.
To reliably free the memory, use the following:
void clear_decoy() {
vector().swap(decoy);
}
This creates a temporary empty vector (with little or no memory allocated), swaps this with decoy so that the memory is now owned by the temporary, then destroys the temporary, freeing the memory.