Next step on reference counting topics

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Tue May 13 08:22:38 PDT 2014


On 05/13/2014 05:11 PM, Andrei Alexandrescu wrote:
> On 5/13/14, 6:41 AM, Dicebot wrote:
>> On Monday, 12 May 2014 at 19:00:33 UTC, Andrei Alexandrescu wrote:
>>> For that I'm proposing we start real work toward a state-of-the-art
>>> std.refcounted module. It would include adapters for class, array, and
>>> pointer types, and should inform language improvements for qualifiers
>>> (i.e. the tail-const problem), copy elision, literals, operators, and
>>> such.
>>
>> We don't have language tools to do it. Main problem with implementing
>> reference counted pointers as structs is that you are forced to abandon
>> polymorphism:
>>
>> class A {}
>> class B : A {}
>>
>> void foo(RefCounted!A) {}
>>
>> void main()
>> {
>>      RefCounted!B b = new B();
>>      foo(b); // no way to make it work
>> }
>>
>> This severely limits applicability of such library solution, especially
>> when it comes to something like exceptions.
>
> "alias this" should be of help here. Could you please try it? Thanks! --
> Andrei
>

class A{
     RefCounted!A r(){ ... }
}

class B : A {
     override RefCounted!B r(){ ... } // ...
}

RefCounted!B[] b;
RefCounted!(const(A))[] a=b; // ...

etc.


More information about the Digitalmars-d mailing list