foreach(r; requests) { r.concider(); }
Gor Gyolchanyan
gor.f.gyolchanyan at gmail.com
Fri Nov 4 06:10:07 PDT 2011
This is perfect! No need for extra syntax :-)
Thanks a lot! :-)
On Fri, Nov 4, 2011 at 5:01 PM, Christophe <travert at phare.normalesup.org> wrote:
> "Steven Schveighoffer" , dans le message (digitalmars.D:146563), a
> écrit :
>
> The foreach delegate syntax already allow you to have parametrized
> iteration over a structure !
>
> Actually, the delegate do not have to be returned by the & operator, it
> can be returned by a function. It's a bit awkward first, but then it's
> easy to use:
>
> struct Iterable
> {
> int delegate(int delegate(ref int)) inReverse()
> {
> return ()
> {
> int result = 0;
> foreach(int i; 0..100)
> {
> auto t = 99-i;
> if((result = dg(t)) != 0) break;
> }
> return result;
> }
> }
>
> int delegate(int delegate(ref int)) byStep(int step)
> {
> return()
> {
> int result = 0;
> foreach(int i; iota(0, 100, step))
> {
> auto t = i;
> if((result = dg(t)) != 0) break;
> }
> return result;
> }
> }
> }
>
>
> int main()
> {
> Iterable it;
> foreach (i; it.inReverse) writeln(i);
> foreach (i; it.byStep(2)) writeln(i);
> }
>
>
> There is no need to add a special syntax to do what you want !
>
> Maybe there should be a bit more documentation about this.
>
More information about the Digitalmars-d
mailing list