Associative Array - where's my error?

bearophile bearophileHUGS at lycos.com
Thu Apr 28 03:15:04 PDT 2011


Jesse Phillips:

> Casting types is making statements about the type, it is not converting the type (in general). You must have inserted the cast because the compiler said s[1] wasn't immutable and figured you could "force it" into being so. In such cases the compiler is telling something is wrong and you are saying "I don't care. I know I'm right." Don't use cast, to!() is much safer.

You have written a nice explanation of the situation, and indeed if you take care of using casts correctly, this situation is not bad. But in practice I think people will not use casts so carefully. This is why I have suggested a different design, essentially: the by line dups on default and doesn't do it on request (this difference is expressed with two different function names or a template argument boolean, etc). So when you don't know what you are doing the code works correctly.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list