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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Sep 18 02:06:48 PDT 2015


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

--- Comment #4 from bearophile_hugs at eml.cc ---
(In reply to Jonathan M Davis from comment #3)

> Honestly though, this seems like an abuse of the in
> operator to me. in is really intended for lookup in containers. It's
> definitely not a range operation.

There's a very nice "in" operator in D, that most other languages miss, and
it's quite under-used, mostly for irrational reasons.


> in must be no worse than O(log n) or it is inappropriate to use it. And
> given how iota works, that can't possibly be done in anything better than
> O(n) in the general case, though it would be possible to implement it for
> integers specifically. 

I agree. One solution is to not compile the "in" if the search is slower than
O(log n), but it doesn't sound very nice.


> A better alternative would be to add find/canFind as a member function to iota

Using "in" for ranges like iota is more natural (here "natural" means that it
requires the programmer to remember less things) than using find/canFind, but
they seem acceptable.

--


More information about the Digitalmars-d-bugs mailing list