New set class

Michiel nomail at please.com
Mon Feb 26 03:29:28 PST 2007


Stephan Diehl wrote:

>> I have written a new class to represent sets, with several useful
>> features. Uploaded for your review and free use. I don't know much about
>> open source and licensing, but I request that if you use the class, that
>> you keep my name in the author section of the documentation.
>>
>> http://files.michiel.eu/set.d
>>
>> Tell me what you think.
>>
> 
> excelent. I somewhat missed some subset operations. If it were up to me,
> I'd use the opCmp operator for this (just like they do in python).

You're right! I missed the subset operations. :)

Unfortunately the opCmp operator is taken. Implementing that correctly
allows a set to be a key-type for an associative array (or the type of
another set).

I can't make it double as a subset operation, because sets would have to
be declared equal if one is not subset of the other. Even if they are
not, indeed, equal. This would break their proper definition.

For a moment I was tempted to use the shifting operators, because
they're only one character apart. But I don't think I like it. They
already have a non-shifter use (right, Walter? :)). A third would be
confusing. Besides, <<= (which would mean: non-strict subset) is
recognized as an op= (or: opAssign) operator.

I also considered the 'in' operator for non-strict subset, but it's
already used as a membership operator, and overloading it for this would
also be confusing.

I will just create a function for it.

-- 
Michiel



More information about the Digitalmars-d mailing list