O(1) dictionaries

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Thu Nov 15 08:42:41 PST 2007


mandel wrote:

> Jari-Matti Mäkelä Wrote:
> 
>> mandel wrote:
>> > The dict may also change order when words are added and quite possibly
>> > regrouped. The entire alignment will be hard to maintain.
>> 
>> That's no good excuse to not use templates :P :
>> 
> [temlate kungfu]
>> 
>> mixin(RealEnum!("Word", "dict", "Hello", "Bye"));
>> 
>> CTFE would produce smaller binaries though.
> 
> Your template looks like it does it's jobs quite nicely - thx.
> 
> The reason I try to avoid templates is that they often look like
> an entry for an obfuscation competition. ;>

Hide them in __dontlookhere.d :)

> 
> Templates in D (in even much more in C++) are hard to understand,
> they don't look like just compile time D code but like a new language.
> (well, I guess the D compilers may need an integrated scripting engine to
> execute D code at compile time).

I hope you use CTFE instead in a "production code" since the templates have
typename limitations and bloat the executable. I pasted some old since I
wasn't sure if CTFE supports varargs now and happened to have the old code
around.

> 
> And as many developers, I try to avoid code templates if there is no real
> benefit or if they stay simple enough for other devs to understand at
> first sight.
> 
> I only use hackish code in speed critical sections (not like NASA, but
> critical in the sense of overall program speed). well, dictionaries in my
> applications may fit in this role. :}

I agree mixins would be cleaner if you could do macro like stuff on a bit
higher level than now and if they worked in more places (for example inside
switches).



More information about the Digitalmars-d mailing list