DIP44: scope(class) and scope(struct)

Walter Bright newshound2 at digitalmars.com
Sat Aug 24 18:50:11 PDT 2013


On 8/24/2013 1:09 PM, H. S. Teoh wrote:
> On Sat, Aug 24, 2013 at 12:27:37PM -0700, Walter Bright wrote:
> [...]
>> Not a bad idea, but it has some issues:
>>
>> 1. scope(failure) takes care of most of it already
>>
>> 2. I'm not sure this is a problem that needs solving, as the DIP
>> points out, these issues are already easily dealt with. We should be
>> conservative about adding more syntax.
>>
>> 3. What if the destructor needs to do more than just unwind the
>> transactions? Where does that code fit in?
>
> I think it's unhelpful to conflate scope(this) with dtors. They are
> related, but -- and I guess I was a bit too strong about saying dtors
> are redundant -- if we allow both, then scope(this) can be reserved for
> transactions, and you can still put code in ~this() to do non-trivial
> cleanups.

If you take out automatic dtor generation, I see no difference between 
scope(this) and scope(failure).


>> 4. The worst issue is the DIP assumes there is only one constructor,
>> from which the destructor is inferred. What if there is more than
>> one constructor?
>
> This is not a problem. If there is more than one constructor, then only
> those scope(this) statements in the ctor that were actually encountered
> will trigger when the object reaches the end of its lifetime.

Do you mean multiple dtors will be generated, one for each constructor?



More information about the Digitalmars-d mailing list