Sets

Sean Kelly sean at f4.ca
Mon Feb 5 11:32:18 PST 2007


Michiel wrote:
> Derek Parnell wrote:
> 
>> I just use: bool[Keytype] setName;
> 
> The problem is that the set of possible keys isn't fixed (I'll often use char[] as
> key-type). So with your idea, there are two possibilities for elements not in the
> set. Either they're not in the array at all, or they are, but their value is false.
> 
> This gives me a very PHPish feeling. :)
> 
> I'd feel better about it if sets were built into D. But I know using a dummy value
> is an option. And that's what I'll use if I have no other choice.

The behavior for sets was cleaner before their behavior was changed such 
that an opIndex lookup throws an exception if the lookup fails. 
Previously, it would return the default value, which for bool would be 
'false'.  Insertions were still a bit messy as setName[key] = true, but 
it was better than nothing.  Personally, I'm not fond of how AA indexing 
and 'in' works now.  It feels like a kludge.


Sean



More information about the Digitalmars-d mailing list