Uniform Function Call syntax for properties

Stanislav Blinov blinov at loniir.ru
Fri Oct 8 07:37:20 PDT 2010


  08.10.2010 17:46, Steven Schveighoffer пишет:
> On Fri, 08 Oct 2010 09:30:59 -0400, Denis Koroskin <2korden at gmail.com> 
> wrote:
>>
>> C# uses 'this' keyword for that purpose:
>>
>> @property int set(this int x, int y)
>> {
>>      x = y;
>> }
>>
>>
>> @property int get(this const(int) x)
>> {
>>      return x;
>> }
>>
>> int a = 1;
>> a.set(42); // a is 42 now
>> 3.set(42); // fails to compile, 3 is of type const(int)
>
> Using this is a good idea, but I don't think we should automatically 
> ref the value.  Also this is already a symbol name, can't we just use 
> it?  What I think might be a good idea is to *name* the target this, 
> and then just allow the normal adornments to describe the type.  i.e.:
>
> @property int set(ref int this, int y) {}
>
> will work only for lvalues, whereas
>
> @property int set(int this, int y) {}
>
> works for rvalues also.  The
>
> What do you think?
>
Looks tasty, and besides that's exactly how class/struct methods 
actually look.




More information about the Digitalmars-d mailing list