properties as lvalues

BCS BCS at pathlink.com
Mon May 15 14:14:47 PDT 2006


cschueler wrote:
> From the specs:
> 
> Note: Properties currently cannot be the lvalue of an op=, ++, or -- operator. 
> 
> This strikes me, as I thought this was very easy to do - just have the access
> function return a reference to the value. Oh wait, there are no references in D
> (at least I didn't find them in the specs)? I think C++ has explicit references
> for a reason, and this might be a hint why this is so.
> 
>

another hitch on allowing get/set on a property is the case where the 
value is not actually part of the object or is checked on the set


class Accept
{
	bool[10] bools;

	int count()
	{
		int ret = 0;
		foreach(b; bools)
			b ? ret++: ret;
		return ret;
	}

	void count(int c)
	{
		if(c >= bools.length) throw new Error("Bad");

		int i;
		for(i=0; i<bools.length; i++)
			if(!(bools[i] ? c--; c) break;

		while(i<bools.length)
			bools[i--] = false;
	}

}




More information about the Digitalmars-d mailing list