handful and interval
Dmitry Olshansky
dmitry.olsh at gmail.com
Sun Sep 2 08:29:18 PDT 2012
On 02-Sep-12 18:22, Andrei Alexandrescu wrote:
> I'd like to add a simple function to std called "handful". It would
> return a small, read-only set of which main facility is membership test:
>
> string a = "class";
> if (a in handful("struct", "class", "union"))
> {
> ...
> }
>
> Would it be generally useful, and if so what module does it belong to?
>
>
I wouldn't question utility but rather the implementation of the above.
One thing I'd love to see is thing like
handful!("struct", "class", "union")
that does pre-process contents at compile time to speed up search.
In other words it's possible to not only come close to a series of a ==
"struct" || a == "class" || a == "union" but surpass it.
At the very least handful!(a,b,c) can take expression tuple and make
x in handful!(a,b,c) lower to:
return x == a || x == b || x == c;
even for run-time variables a, b & c.
--
Olshansky Dmitry
More information about the Digitalmars-d
mailing list