DIP1000: Scoped Pointers

Mike via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Aug 16 18:57:50 PDT 2016


On Wednesday, 17 August 2016 at 01:42:00 UTC, Walter Bright wrote:

>> Can you please clarify the current implementation `scope`, and 
>> what DIP1000
>> proposes to change with respect to the current implementation?
>
> It just adds to the existing compiler implementation of 
> 'scope'. It has nothing to do with std.typecons.scoped.

Ok, but the deprecations page [1] gives this example...

class A
{
     int x;
     this(int x) { this.x = x; }
}

void main()
{
     A obj;
     {
         scope A a = new A(1);
         obj = a;
     }
     assert(obj.x == 1);  // fails, 'a' has been destroyed
}

... as a deprecated pattern, and corrected with ...

class A
{
     this(int x) { }
}
void main()
{
     auto a = std.typecons.scoped!A(1);
}

However, in DIP1000, the examples use the above deprecated 
pattern extensively.  So what's the story?  Does the deprecations 
page [1] need an update?

[1] 
http://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack


More information about the Digitalmars-d-announce mailing list