How to check member function for being @disable?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 13 10:52:48 PDT 2016


On Tuesday, September 13, 2016 17:29:26 Uranuz via Digitalmars-d-learn wrote:
> OK. Seems that there is nothing that I could do more about my
> example code.. So the best way to be sure if something is
> assignable property is to try assign to it and test whether it
> compiles. The question was because utill this moment I somehow
> was living without __traits(compiles..). Seems that my use cases
> just was not enough complicated... Thanks for the answers.
>
> It could be good idea to have __traits( isDisable ... ) or
> something for it. I admit that not only '@disabled this();'
> regular methods could me marked @disable too..

The main places that I can think of at the moment where @disable makes sense
is for disabling default initialization - @disable this(); - and disabling
copying - @disable this(this);. It's really intended for disabling features
that would normally be there. I don't know why it would ever make sense to
@disable a normal function. Why would it even exist if it were @disabled?
So, for the compiler to allow @disable on normal functions sounds like a bug
to me - or at least an oversight in the design and implementation of
@disable - but maybe there's a legitimate reason that I'm not thinking of at
the moment. Regardless, testing for it is as simple as testing whether it
can be called or not, and you have to worry about that in a number of cases
anyway, because the access level of the function may be such that you can't
call it (e.g. it's private, and the code in question is not in the module
trying to call it). So, I don't really see what testing for @disable
specifically would buy you.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list