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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Sep 4 12:50:18 PDT 2015


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

Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang at jmdavisProg.co
                   |                            |m

--- Comment #3 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
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. 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.

A better alternative would be to add find/canFind as a member function to iota
in the cases where it would be more efficient than the std.algorithm
implementation. Then any code which uses find/canFind with UFCS with iota and
integral values would get a performance boost (including in generic code)
rather than just this specific case where the code is specifically written for
iota.

--


More information about the Digitalmars-d-bugs mailing list