between and among: worth Phobosization?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Dec 16 12:38:51 PST 2013


bool between(T, U1, U2)(T v, U1 lo, U2 hi)
{
     return v >= lo && v <= hi;
}

uint among(T, Us...)(T v, Us vals)
{
     foreach (i, U; Us)
     {
         if (v == vals[i]) return i + 1;
     }
     return 0;
}

Add?


Andrei


More information about the Digitalmars-d mailing list