between and among: worth Phobosization?
Timon Gehr
timon.gehr at gmx.ch
Mon Dec 16 13:49:18 PST 2013
On 12/16/2013 09:38 PM, Andrei Alexandrescu wrote:
> bool between(T, U1, U2)(T v, U1 lo, U2 hi)
> {
> return v >= lo && v <= hi;
> }
> ...
There's the issue of different possibilities for inclusive/exclusive end
points. Maybe we want to add a template parameter taking values from
["[)","()","(]","[]"]. Even then it is not too clear what the default
should be. (Probably "[)".)
> uint among(T, Us...)(T v, Us vals)
> {
> foreach (i, U; Us)
> {
> if (v == vals[i]) return i + 1;
> }
> return 0;
> }
> ...
I have my own version of this. I vote add.
More information about the Digitalmars-d
mailing list