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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun May 19 12:03:45 PDT 2013


On 5/19/13 1:41 PM, deadalnix wrote:
> On Sunday, 19 May 2013 at 04:57:15 UTC, Walter Bright wrote:
>> On 5/18/2013 8:54 PM, deadalnix wrote:
>>> On Sunday, 19 May 2013 at 01:20:31 UTC, Walter Bright wrote:
>>>> I understand that. But the rationale you gave for having a default
>>>> constructor
>>>> was to be able to disable default construction.
>>>
>>> RAII or construction based on template parameters.
>>
>> I know what default constructors are used for in C++. That wasn't what
>> I asked, though. I asked for compelling rationale.
>>
>
> 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.

No need for a default constructor. You pass the current value as a 
constructor parameter.

Andrei




More information about the Digitalmars-d mailing list