disable all member function calls for rvalues?

Michel Fortin michel.fortin at michelf.com
Fri Dec 25 08:59:36 PST 2009


On 2009-12-25 11:13:10 -0500, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

>> If you could pass "this" by value instead of ref, it'd solve the 
>> problem nicely:
>> 
>>     struct MyRange {
>>         MyRange opSlice(int, int) @byvalue;
>>         void length(int) @property;
>>     }
>> 
>> Here you can call opSlice on a lvalue since it takes the "this" 
>> argument by value, but you can't call length(int) because it takes it 
>> by ref.
>> 
> 
> I've seen that. The only problem I see with that is that it complicates 
> the language. Ideally some sort of inference could be applicable.

If we ever get that "universal calling syntax" thing, where any 
function can be called as if it were a member function, it would be 
super simple:

	void MyRange opSlice(MyRange this, int, int) {...}

Just don't put "ref" in front of the first argument.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list