Sometimes it's nice to start over. In C++ I can employ this following simple manoeuvre:
{
T x(31, Blue, false);
x.~T(); // enough with the old x
::new (&x) T(22, Brown, true); // in with the new!
// ...
}
At the end of the scope, the destructor will run once again and all seems well. (Let's also say T
is a bit special and doesn't like being assigned, let alone swapped.) But something tells me that it's not always without risk to destroy everything and try again. Is there a possible catch with this approach?