On Fri, Apr 01, 2016 at 07:26:46PM +1100, Daniel Murphy via Digitalmars-d wrote: > On 1/04/2016 6:24 AM, deadalnix wrote: > >Pretty much as per title. I has that in the back of my mind for a > >while. Would that work ? > > Don't forget that builtin AAs have been an epic disaster, and this > would require an appalling amount of effort to implement in the > compiler types, ctfe, druntime, new traits etc. > > Phobos seems like a better place - and while not quite as concise, the > syntax should still be pretty intuitive.
Yeah, having yet another language builtin is a bad idea, it complicates the compiler and ties you to a specific implementation of sets. Why not just Set!T instead, implemented in Phobos? Sets behave pretty much like bit arrays, so for operations you can have: Set!T s1, s2, s3 T e; s1.add(e); s2.remove(e); auto s3 = s1 | s2; // union auto s4 = s1 & s2; // intersection auto s5 = s1 * s2; // cartesian product auto s6 = s1 - s2; // set difference auto s7 = s1 ^ s2; // symmetric difference which gives us nice enough syntax for standard set operations, perfectly implementable via operator overloading in a library. (Note: above operators are only suggestions.) I don't think AA syntax is very well-suited for sets. (What on earth is `set[x] = true` supposed to mean?! You want to add an element to the set, not to set an element to true in the set. It doesn't make sense mnemonically.) T -- What did the alien say to Schubert? "Take me to your lieder."