Range of random numbers

Christophe travert at phare.normalesup.org
Tue Apr 24 04:50:31 PDT 2012


"bearophile" , dans le message (digitalmars.D.learn:35108), a écrit :
> What about (untested):
> 
> auto uniformRange(T1 lower, T2 upper) {
>      return count().map!(_ => uniform(lower, upper))();
> }

That looks like a workarround, not meaningful code.

How about
  return repeat(_ =>uniform(lower, upper)).map!(x => x())();
?

We could also use a template to make a range out of a delegate and avoid 
this workarround...

struct RepeatDg(T)
{
  T delegate() dg;
  this(T delegate() dg_) { dg = dg_; }

  @property enum bool empty = false;
  @property T front() { return dg(); }
  @property void popFront() {}
}
  


More information about the Digitalmars-d-learn mailing list