between and among: worth Phobosization?
Marco Leise
Marco.Leise at gmx.de
Tue Dec 17 06:38:46 PST 2013
Am Mon, 16 Dec 2013 14:31:16 -0800
schrieb "H. S. Teoh" <hsteoh at quickfur.ath.cx>:
> On Mon, Dec 16, 2013 at 01:45:38PM -0800, Walter Bright wrote:
> > 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.
> [...]
>
> bool between(string op1=">=", string op2="<=", T, U1, U2)
> (T v, U1, lo, U2 hi)
> {
> return mixin("v" ~ op1 ~ "lo") &&
> mixin("v" ~ op2 ~ "hi");
> }
>
> x.between(y, z); // y <= x <= z
> x.between!(">", "<")(y, z); // y < x < z
> // etc.
>
>
> T
Compare:
a) import std.something; x.between!(">", "<")(y, z);
b) y < x && x < z
now which would you use? :-)
--
Marco
More information about the Digitalmars-d
mailing list