property-like data members

spir denis.spir at gmail.com
Mon Jan 3 06:56:30 PST 2011


On Mon, 03 Jan 2011 08:34:42 -0500
"Steven Schveighoffer" <schveiguy at yahoo.com> wrote:

> Yes, just use a data member:
> 
> struct MyRange {
>     int front;
>     bool empty;
>     void popFront();
> }
> 
> A property is actually supposed to work just like a field.
> 
> There is no need for new syntax.

Hum, does not work by me (else I would not have posted ;-)
The compiler rejects the code complaining for missing opApply (which I interpret as meaning it does not recognize a range in such an interface). indeed, it works if manually implement iteration like for instance:
	while (! coll.empty) {
	    auto element = coll.front;
	    use(element);
	    coll.popFront();
	}
But then there no property in play (I mean the compiler does not expect a property set implementing a range).

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list