between and among: worth Phobosization?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Dec 16 14:31:16 PST 2013


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

-- 
"I'm not childish; I'm just in touch with the child within!" - RL


More information about the Digitalmars-d mailing list