On 10/27/2015 07:57 AM, Manu via Digitalmars-d wrote:
On 27 October 2015 at 21:41, Andrei Alexandrescu via Digitalmars-d
<[email protected]> wrote:
It follows that if we want safe reference counting, there must be language
support for it. One possibility is to attach an attribute to the class
definition:
@safe @rc class Widget {
...
}
An attribute? Is presence of opInc()/opDec() insufficient? Would the
attribute signal fabrication of some default opInc/opDec operators
applicable for general use?
You're right, opInc/opDec detection would suffice.
Unrelated, and a foreshadowing of the discussion on the lifetime mailing
list: the compiler has ample opportunity to fuse incs/decs together, so
the signatures of these functions is:
void opInc(uint delta);
void opDec(uint delta);
For example, consider:
class Widget {
void fun(Widget, Widget);
}
...
auto w = new Widget;
w.fun(w, w);
In this case the compiler may insert opInc with a value larger than 1
prior to entering the call.
Andrei