Is @property implementable?

Michel Fortin michel.fortin at michelf.com
Wed Mar 2 13:49:40 PST 2011


Consider that currently, using an array as a range is implemented this way:

	int front(int[] array) {
		return array[0];
	}

	int[] array = [1,2,3];
	auto e = array.front;

Currently, this work fine because the compiler treats "array.front" and 
"array.front()" as the same thing, they're both rewritten as 
"front(array)".

Now consider the world of the future where only functions marked with 
@property can use the property syntax, and only functions *not* marked 
with @property can use the function call syntax. Now, for "array.front" 
to work you'd have to label "front" with @property, like this:

	@property int front(int[] array) {
		return array[0];
	}

The problem is that now, for "array.front" to work it'd have to be 
rewritten as "front = array", which does not make any sense.

So what to do? And also, what happens if you want to implement a setter 
for "array.front = 1"?

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



More information about the Digitalmars-d mailing list