digitalmars.D - Is the automatic opAssign exception-safe?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (20/20) Dec 27 2009 Does opAssign still work the way I quote from
Does opAssign still work the way I quote from http://digitalmars.com/d/2.0/struct.html: <quote> S* opAssign(S s) { ... bitcopy *this into tmp ... ... bitcopy s into *this ... ... call destructor on tmp ... return this; } </quote> The reason for the temporary must be exception safety. Otherwise, one would simply destroy *this and then copy from s. Am I correct? Additionally, I suspect that the 'bitcopy's above are actually memberwise copies, calling each member's post-blit function. If so, then a member's post-blit may throw and the above code is not exception-safe anymore. Is the documentation old, and opAssign is in fact exception-safe? If it was never intended to be, then why the temporary? Thank you, Ali
Dec 27 2009