between and among: worth Phobosization?
Walter Bright
newshound2 at digitalmars.com
Mon Dec 16 13:45:38 PST 2013
On 12/16/2013 12:38 PM, Andrei Alexandrescu wrote:
> bool between(T, U1, U2)(T v, U1 lo, U2 hi)
> {
> return v >= lo && v <= hi;
> }
You'd need 4 such functions, < <, < <=, <= <, <= <=, and it just seems like trivia.
>
> uint among(T, Us...)(T v, Us vals)
> {
> foreach (i, U; Us)
> {
> if (v == vals[i]) return i + 1;
> }
> return 0;
> }
This has O(n) behavior, which might be unexpected for the user.
More information about the Digitalmars-d
mailing list