On 12/01/11 06:28, KennyTM~ wrote:
On Jan 11, 11 17:10, Justin Johansson wrote:
On 10/01/11 05:42, Andrei Alexandrescu wrote:
I wrote a simple helper, in spirit with some recent discussions:
unittest
{
assert(1 == either(1, 2, 3));
assert(4 != either(1, 2, 3));
assert("abac" != either("aasd", "s"));
assert("abac" == either("aasd", "abac", "s"));
}
Just my 2 cents and I wonder if there some other way of achieving the
desired functionality of your helper without resorting to overloading
"==" and the consequential violation of the commonly held semantics of
equality.
We could use in instead of ==
if (1 in oneOf(1, 2, 3)) { ... }
if (4 !in oneOf(1, 2, 3)) { ... }
Nice suggestion.
At the end of the day though it basically boils down to having either a
binary operator** or a function for it.
(** preferably excluding "==" and other undesirable operator overloads
of course).