New set class

Bill Baxter dnewsgroup at billbaxter.com
Sat Feb 24 22:20:30 PST 2007


Michiel 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.

If you add an opApply with the signature
    int opApply(int delegate(uint i, inout Type) dg) { ... }

it will allow this kind of foreach too:
    foreach(i, e; myset) {
        ...
    }

Also I would just leave out opApplyReverse.  That way using it is a 
compile-time error.  Or if you're dead set on it, at least have it throw 
an exception.  I believe assert() is a no-op in release builds, meaning 
your program will fail in strange ways in release.  Actually I'm 
surprised that compiles without a return statement.

Finally
    Set!(T[0]) set(T...)(T elements)
why not just
    Set!(T) set(T)(T elements...) ??

Have you looked at the HashSet implementation in Tango for comparison?

--bb



More information about the Digitalmars-d mailing list