Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)

Walter Bright newshound2 at digitalmars.com
Sun May 19 11:27:06 PDT 2013


On 5/19/2013 10:41 AM, deadalnix wrote:
> I have bunch of code that goes like :
>
> auto oldVar = var;
> scope(exit) var = oldVar;
>
> This is begging for a RAII solution where I pass var as template parameter but
> would require default constructor. This is an actual problem I have right now as
> all save/restore are harder and harder to keep in sync for no reason and
> generate a lot of boilerplate.
>
> This is a problem I have right now that default constructor would solve, and
> this isn't the first time I hit that need.

oldVar isn't being default constructed in your example, nor can I see why you'd 
need a default constructor in order to use RAII for save/restore.



More information about the Digitalmars-d mailing list