between and among: worth Phobosization? (reprise)

Vladimir Panteleev via Digitalmars-d digitalmars-d at
Thu Mar 26 11:41:48 PDT 2015

On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu 
> On 12/16/13 12:38 PM, Andrei Alexandrescu wrote:
>> bool between(T, U1, U2)(T v, U1 lo, U2 hi)
>> {
>>     return v >= lo && v <= hi;
>> }
>> Add?
> Looks like among() has proven its worth since we introduced it. 
> Now I somehow forgot between() didn't make it, and reviewed 
> some code at work assuming it exists!

I don't know if it's been mentioned yet, but there exists an 
optimization for between with integer arguments:

bool between(T, U1, U2)(T v, U1 lo, U2 hi)
	if (is(T:long) && is(U1:long) && is(U2:long))
     return cast(Unsigned!T )v  - cast(Unsigned!U1)lo
         <= cast(Unsigned!U2)hi - cast(Unsigned!U1)lo;

For this reason, I think this makes "between" non-trivial, so it 
is worth adding.

More information about the Digitalmars-d mailing list