Proposal for a set handling library

bearophile bearophileHUGS at lycos.com
Wed Jan 1 16:44:47 PST 2014


Raphaël Jakse:

>         auto E = new Set!int([1,2,3,4]); // it is possible to 
> declare an empty set

You can add a factory helper:
auto e = set([1, 2, 3, 4]);

Or even:
auto e = set(1, 2, 3, 4);


>         writeln("union: ", E.Union(F));
>         writeln("inter: ", E.Inter(F));
>         writeln("symmetric difference: ", E.SymDiff(F));
>         writeln("minus: ", E.Minus(F));
>         writeln("Powerset: ", E.Powerset);

In idiomatic D all the member functions start with a lowercase 
letter.

And a little operator overloading helps, look at the Python set() 
for a nice API.


>             // beware, because S is an untyped set (Set!() or 
> Set!Object),

Probably in idiomatic D you use templates, so Set!Object is a 
very uncommon usage, unlike Java.


> Should Phobos have something similar built in?

A set is a good thing to have in Phobos, but the API and design 
should be a little different from yours.

Bye,
bearophile


More information about the Digitalmars-d mailing list