disable all member function calls for rvalues?

Michel Fortin michel.fortin at michelf.com
Thu Dec 24 07:10:22 PST 2009


On 2009-12-23 12:53:54 -0500, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

>> Is this one of them?
>> 
>>     int[5] array = [1, 2, 3, 4, 5];
>>     array[1..3] = [0, 0];
>> 
>> Or, more likely returning a non-built-in range type is one of them:
>> 
>>     MyContainer container = [1, 2, 3, 4, 5];
>>     container[1..3] = [0, 0];
>> 
>> and you'll have to write it like this:
>> 
>>     MyContainer container = [1, 2, 3, 4, 5];
>>     MyRange range = container[1..3];
>>     range = [0, 0];
> 
> That's just mean! :o)
> 
> Guess I need to acquiesce. Thanks Michel for the example.

Well, if we had a way for saying we want to pass the "this" argument by 
value, it'd solve the problem nicely. For the example above to work:

	struct MyRange {
		void opAssign(...) @byvalue;
	}

Only functions with the @byvalue attribute (as well as const and 
immutable functions) could be called on an lvalue. So you could allow 
assignment and disallow changing the length of the range on an lvalue.

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




More information about the Digitalmars-d mailing list