Reference counted containers prototype

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 27 06:23:48 PST 2011


On 12/27/11 12:08 AM, Andrej Mitrovic wrote:
> On 12/27/11, Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>  wrote:
>> It actually does, as per the unittests. Even if it currently does by
>> @property being too lax, it should continue to work.
>
> It actually doesn't:
>
> struct FooImpl
> {
>      int _x;
>      @property int x() { return _x; }
>      @property void x(int val) { _x = val; }
>
>      auto dup() { return FooImpl(); }
>      auto dispose() { }
> }
>
> void main()
> {
>      RefCounted!FooImpl foo;
>      foo.x = 1;  // NG
> }
>
> Sure you could make a property return ref, but that's circumventing
> the setter and allowing direct access to the field from client-code.
> I've ran into this issue before when playing with opDispatch but I
> couldn't figure out a workaround.

Sorry for being unclear - when I wrote "should work" I meant "it's a bug 
if it doesn't".

>> So construction of objects
>> needs to be handled by RefCounted itself - e.g. by forwarding
>> constructor parameters.
>
> But it doesn't do that currently?

The prototype does not define a variadic forwarding constructor.


Andrei


More information about the Digitalmars-d mailing list