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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Sep 3 06:58:06 PDT 2015


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

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |ag0aep6g at gmail.com
         Resolution|INVALID                     |---

--- Comment #2 from ag0aep6g at gmail.com ---
(In reply to Jack Stouffer from comment #1)
> 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;
>     }
> }

The request is not for Python's `in`. The request is for a succinct way to do
what Python's `1 < foo(2) < 10` does. The suggested solution with D's `in`
would of course not do a linear search. Reopening.

--


More information about the Digitalmars-d-bugs mailing list