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