Sets / associative arrays with void values?

Vladimir Panteleev tehcybershadow at gmail.com
Sat Jan 6 16:05:06 PST 2007


I've been wondering whether D supported sets, or something similar. What I  
have in mind isn't unlike associative arrays, but without values: an  
unordered list with quick look-up and simple addition/removal of elements,  
yet still capable of enumeration, etc.

I followed my intuition and tried to declare an associative array with a  
"void" value type:

void[int] foo;

To my surprise, it compiled. And even the "in" operation and the .keys and  
.values properties worked fine (or as fine as they can work with an empty  
associative array).

Of course, the question comes: how would one add keys to such a construct?  
The practical answer is obvious: use a real "dummy" data type (bit, for  
example) as the value type, but I find it a shame that declaring such  
constructs is allowed - yet you can't really use them.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Fix obvious typo in e-mail address to reply.



More information about the Digitalmars-d mailing list