On 02/09/2011 08:06 PM, Daniel Gibson wrote:
Also using X in 1..4 is in D is pretty bad if you just want to check if 1<X<4
(or even more when checking 1<X<100) because it has a much higher overhead -
even though it may be technically O(1) because 4 or 100 is a constant) than just
doing two comparisons. So IMHO using X in 1..4 or x in iota(1,4) should not be
encouraged. (X in [1,3,4,8] is different.)

I don't understand your point, here. opIn (or rather opIn_r) ids just 2 comparisons as well for whatever represents an interval i..j. Simulation below.

Denis

struct Interval {
    int min, maxPlusOne;
    bool opIn_r (int n) {
        return (n >= min) && (n < maxPlusOne);
    }
}
unittest {
    auto ii = Interval(1,4);
    auto ints = [-1,0,1,2,3,4,5];
    foreach (i ; ints) writefln ("%s ? %s", i, i in ii);
}
==>
-1 ? false
0 ? false
1 ? true
2 ? true
3 ? true
4 ? false
5 ? false

--
_________________
vita es estrany
spir.wikidot.com

Reply via email to