[Issue 11252] "in" operator for std.range.iota

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Aug 22 12:00:59 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=11252

Jack Stouffer <jack at jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jack at jackstouffer.com

--- Comment #1 from Jack Stouffer <jack at jackstouffer.com> ---
This enhancement request makes no sense, as the "in" operator in Python and D
do two completely different things.

To replicate the Python behavior, you can do the following:

import std.stdio, std.range, std.algorithm.searching;

void main() {
    if (iota(1, 10).countUntil(foo(2)) > -1) {
        "yes".writeln;
    }
}

But I don't see why you would want to, as this is much faster:

void main() {
    immutable int temp = foo(2);
    if (temp >= 1 && temp <= 10) {
        "yes".writeln;
    }
}

--


More information about the Digitalmars-d-bugs mailing list