Detecting a property setter?

Rory McGuire rmcguire at neonova.co.za
Mon Jul 19 14:41:23 PDT 2010


On Mon, 19 Jul 2010 22:42:51 +0200, Philippe Sigaud  
<philippe.sigaud at gmail.com> wrote:

> On Mon, Jul 19, 2010 at 22:06, Simen kjaeraas <simen.kjaras at gmail.com>  
> wrote:
>> template hasSetter(alias func) if (isCallable!(func)) {
>>    enum hasSetter = isProperty!(func) &&
>>        is( typeof( (){ func = ReturnType!(func).init; } ) );
>> }
>>
>
> In that case, for the second func, the one you call ReturnType on, how  
> does the compiler knows it must take the ref uint one (the getter) and  
> >not the void func() one?
>
>
> Philippe
>
>

Simen is using the fact that the compiler already has to figure out if  
there is an overload that matches the requirements. So it ends up
taking the only one that works. Since it seems to ignore the ref return  
type property, the property that takes an uint argument must have a
higher precedence (gets checked if it works first).
I wonder if its because Walter probably implemented function overloading  
before properties and ref return types. Hopefully its a language
feature and not just a implementation side effect.

-Rory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100719/ee198f01/attachment.html>


More information about the Digitalmars-d-learn mailing list