between and among: worth Phobosization?

Vladimir Panteleev vladimir at thecybershadow.net
Tue Dec 17 06:44:11 PST 2013


On Monday, 16 December 2013 at 20:38:52 UTC, Andrei Alexandrescu 
wrote:
> bool between(T, U1, U2)(T v, U1 lo, U2 hi)
> {
>     return v >= lo && v <= hi;
> }

Careful:

assert(between(0u, -1, 1)); // fails

Assuming no overflows, a faster implementation would be:

return v-lo <= hi-lo;


More information about the Digitalmars-d mailing list