yield iteration

Christophe Travert travert at phare.normalesup.org
Tue Jul 31 01:39:13 PDT 2012


"bearophile" , dans le message (digitalmars.D:173647), a écrit :
> Turning that in D code that uses opApply is not hard, but the 
> code inflates 3X, and you can't use most std.algorithm on it.

I believe most std.algorithm that work on input range could be made to 
work with opApply, or opApply-like delegates. It just wouldn't be 
particularly efficient unless agressive inlining is used.

For example, filter could work like this for opApply-like delegates:

template filter(pred)
{
  auto filter(T)(int delegate(int delegate(ref T)) apply)
  {
    return (int delegate(ref T) dg)
    {
      return apply( (ref T t) { return pred(t)? dg(t): 1; });
    }
  }
}

-- 
Christophe


More information about the Digitalmars-d mailing list