between and among: worth Phobosization?

Byron byron.heads at gmail.com
Tue Dec 17 08:43:58 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;
> }
>
> uint among(T, Us...)(T v, Us vals)
> {
>     foreach (i, U; Us)
>     {
>         if (v == vals[i]) return i + 1;
>     }
>     return 0;
> }
>
> Add?
>
>
> Andrei


I don't know why we can do this instead:

if(foo in ["alpha", "beta", "delta"] ) {

}

basically have an opIn operator  x in y -> y.opIn(x)
U* opIn(T, U)(T key)
can define in runtime for arrays, and allow custom ones to be 
defines

and

if(1 < x <= 10) {

}

I remember this being shot down before...




Both of these are easier to read, and are more natural.  They 
also cover more cases.


More information about the Digitalmars-d mailing list