std.range.iota enhancement: supporting more types (AKA issue 10762)

Iain Buclaw ibuclaw at gdcproject.org
Sun Dec 29 03:15:28 PST 2013


On 27 Dec 2013 20:33, "H. S. Teoh" <hsteoh at quickfur.ath.cx> 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.  :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20131229/0d392bec/attachment.html>


More information about the Digitalmars-d mailing list