How about a Hash template?

Peter Alexander peter.alexander.au at gmail.com
Thu Apr 28 08:48:52 PDT 2011


On 28/04/11 4:24 PM, Andrej Mitrovic wrote:
> "InSet!(var, values...)."
>
> That wouldn't work because var is known only at runtime. Ideally I'd
> like to write something like:
>
> string needle = "foo";
> if (needle.InSet!("bar", "barfoo", "doo", "foo")) { }
>
> And InSet would mixin and call a function such as:
> bool inSet(string needle)
> {
>      if (needle = "bar" || needle = "barfoo" || needle == "doo"
>          || needle == "foo") return true;
>      return false;
> }
>
> However I don't think this is possible. I want the string literals to
> be binded at compile time, and needle to be binded at runtime with the
> UFC syntax. However in this case the compiler tries to pass needle as
> a compile-time argument, which fails.

What's wrong with

InSet!(T, T values...)(T needle)

?

string foo = "b";
if (InSet!("a", "b", "c")(foo))
   ...


More information about the Digitalmars-d mailing list