On 27 Dec 2013 20:33, "H. S. Teoh" <[email protected]> wrote: > > On Wed, Dec 25, 2013 at 02:30:45PM +0000, Francesco Cattoglio wrote: > > On Wednesday, 25 December 2013 at 10:58:53 UTC, bearophile wrote: > [...] > > >(A less important enhancement is issue 11252). > > On the other hand, I have honestly no idea whatsoever about how to > > implement this > [...] > > It should only be supported for numeric types (i.e., that support > +, *, /). Here's a crude attempt at it: > > struct Iota(S,T,U) { > S start; > T end; > U step; > > ... // other stuff here > > bool opBinaryRight(string op)(V val) > if (op=="in" && > is(V.init < S.init) && > is((V.init - S.init) % U.init) && > is(T.init >= V.init)) > { > if (val < start || val >= end) > return false; > > // Surprisingly, x%y actually appears to work > // like fmod(x,y) in D for floating point types! > // Not sure how to represent 0 in a generic way > // though. > return ((val - start) % step == 0); > } > } >
For GDC, 'appears to work like' gets turned into 'it calls' fmod(x, y) in D. :)
