Thu, 22 Jan 2009 21:53:02 -0500, Michel Fortin wrote: > On 2009-01-19 18:11:15 -0500, Sergey Gromov <snake.sc...@gmail.com> said: > >> I think "can't" is a bit strong a statement. Let's see: >> >> With opApply: >> >> class progressUpdater(Collection) >> { >> this(Collection c) >> { >> collection_ = c; >> } >> >> int opApply(int delegate(ref ElementType!(Collection)) dg) >> { >> composed_ = dg; >> return collection_.opApply(&fancifier); >> } >> >> private: >> >> int fancifier(ref ElementType!(Collection) el) >> { >> globalOnProgress(); >> return composed_(el); >> } >> >> Collection collection_; >> int delegate(ref ElementType!(Collection)) composed_; >> } > > I think it's the same as this: > > class progressUpdater(Collection) > { > this(Collection c) > { > collection_ = c; > } > > int opApply(int delegate(ref ElementType!(Collection)) dg) > { > int fancifier(ref ElementType!(Collection) el) > { > globalOnProgress(); > return composed_(el); > } > > composed_ = dg; > return collection_.opApply(&fancifier); > } > > private: > > Collection collection_; > } > > Or this: > > class progressUpdater(Collection) > { > this(Collection c) > { > collection_ = c; > } > > int opApply(int delegate(ref ElementType!(Collection)) dg) > { > foreach(ref ElementType!(Collection) el; collection_) > { > globalOnProgress(); > if (dg(el)) > return 1; > } > return 0; > } > > private: > > Collection collection_; > }
Or even this: class progressUpdater(Collection) { this(Collection c) { collection_ = c; } int opApply(int delegate(ref ElementType!(Collection)) dg) { return collection_.opApply( (ref ElementType!(Collection) el) { globalOnProgress(); return dg(el); } ); } private Collection collection_; }