DIP74: Reference Counted Class Objects

Manu via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 28 18:49:18 PST 2015


On 1 March 2015 at 12:21, Andrei Alexandrescu via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 2/28/15 5:43 PM, Manu via Digitalmars-d wrote:
>>
>> I'd like to see a struct with RC operators have implicit calls
>> generated (and elided) for exactly the same set of cases as classes,
>> in terms of construction/destruction/assignment/passing to/from
>> functions.
>
>
> The short answer is that probably won't happen. -- Andrei

*sigh* ... ever, or in DIP74?

I presented my 80% case to you before. I just want this to work efficiently:

extern(C) void inc(void*);
extern(C) void dec(void*);

struct X
{
  void *thing;

  opInc() { inc(thing); }
  opDec() { dec(thing); }
}


X is a struct, not a class.
If DIP74 can't do this efficiently, then it's no use to me.


Do I need to abuse the type system by declaring:
class Opaque
{
  void opInc() { inc(cast(void*)this); }
  void opDec() { dec(cast(void*)this); }
}

That's a really lame thing to do. Debuggers will dereference Y, try
and present a vtable and stuff to me. In the event I want to mirror
the opaque C struct definition on the D side, I can't express it
because class has implicit members which aren't actually there.

What is the resistance to making it work on struct? It just seems like
another arbitrary edge case in the language.


More information about the Digitalmars-d mailing list