How about a Hash template?

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Apr 27 16:10:15 PDT 2011


I often see code written like this:

if (value == somevalue ||
   value == someothervalue ||
   value == yetanothervalue);

You could use the switch statement. But that introduces indentation,
and is rarely used for a couple of values.

I really like the "in" keyword, and I also like hashes since they can
potentially speed up look-ups compared to conventional arrays. So I
thought it would be cool to have a Hash template that constructs an
associative array which you can use especially in if statements when
you just want to know if a runtime value matches some predetermined
value.

Here's my attempt at writing it:
http://codepad.org/c4sYDSyR

Whaddya think?


More information about the Digitalmars-d mailing list