property-like data members
spir
denis.spir at gmail.com
Mon Jan 3 08:22:38 PST 2011
On Mon, 03 Jan 2011 10:27:17 -0500
"Steven Schveighoffer" <schveiguy at yahoo.com> wrote:
> On Mon, 03 Jan 2011 09:56:30 -0500, spir <denis.spir at gmail.com> wrote:
>
> > 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).
>
> That's a bug. isInputRange!S returns true.
>
> There's nothing in the spec that says foreach requires those elements to
> be functions. In fact, empty *does* work as a normal field, i.e. this
> struct is foreachable:
>
> struct S
> {
> @property int front() {return 0;}
> bool empty;
> void popFront() {empty = true;}
> }
>
> Filed:
>
> http://d.puremagic.com/issues/show_bug.cgi?id=5403
>
> -Steve
All right. great that we can do that (provide a plain data member where a property is expected).
denis
-- -- -- -- -- -- --
vit esse estrany ☣
spir.wikidot.com
More information about the Digitalmars-d
mailing list