scope guards

Manu via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 5 03:38:51 PDT 2014


On 5 August 2014 19:37, Atila Neves via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Monday, 4 August 2014 at 14:57:44 UTC, Dicebot wrote:
>
>> On Monday, 4 August 2014 at 04:09:07 UTC, Manu via Digitalmars-d wrote:
>>
>>> Sure, scope() may be useful for this, but it seems in my experience that
>>> destructors almost always perform this without any additional code at the
>>> callsite.
>>>
>>
>> Destructors only work if:
>>
>> a) you already have RAII wrappers provided, otherwise it is much more
>> code to write
>> b) you work with structs, class destruction is non-determenistic
>>
>
> b) And even then, struct destruction can be non-deterministic if they
> happen to be in a dynamic array...
>

'scope' class destruction is deterministic though right?

http://dlang.org/statement.html : there are examples of stuff like this:

scope Foo f = new Foo();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140805/99072545/attachment.html>


More information about the Digitalmars-d mailing list