parameterized lazy expression

BCS ao at pathlink.com
Tue Oct 2 14:55:05 PDT 2007


Reply to freeagle,

> 
> i wanted to make a template representing mathematical sets, that would
> be defined something like MSet!(int)(x > 0 && x < 10, x*2)
> but with the returns and all, it looks weird:
> MSet!(int)((int x) {return x > 0 && x < 10; }, (int x) { return x * 2;
> })
> freeagle
> 

there is one other option

void foo(inout int i, lazy bool b)
{
  int j = 0;
  do
    i = j++;
  while(dg());
}

use like this

int k;
foo(k, k <= 5);

I would consider that an "ugly hack".




More information about the Digitalmars-d-learn mailing list