iota with custom boundary conditions

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Tue Nov 13 05:12:43 PST 2012


A small proposal -- would it be possible, without introducing lots of 
complications, to permit iota to take a template parameter for boundary 
conditions similar to that used for std.random.uniform?

So, iota!"[)"() would give the current iota behaviour of including the start 
point but not the end; iota!"[]" would include beginning and end; iota!"(]" 
would include the end but not the beginning; and iota!"()" would exclude both 
beginning and end.

It certainly has application in my own code where e.g. I'd like to be able to use,

      foreach(x; iota!"[]"(0, 1, 0.05)) { .... }

i.e. to foreach across the closed interval [0, 1] with 0.05 step increments.  I 
can see similar use-cases for the open interval elsewhere, e.g. when I'm dealing 
with a function that will display asymptotic behaviour at the limit values.

Any thoughts?


More information about the Digitalmars-d mailing list