between and among: worth Phobosization?

Jerry jlquinn at optonline.net
Tue Dec 17 07:59:31 PST 2013


Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> writes:

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

+1

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

This seems less useful to me.  What was the example where you found it
useful?

Jerry


More information about the Digitalmars-d mailing list