
At 16:16 2005-05-26, Dominic Herity wrote:
I've often wished that STL sets supported set arithmetic operations. Addition, multiplication and subtraction operators could be overloaded with set union, intersection and difference respectively.
For example: set<char> s1; // s1 <- {} s1 += 'a'; // s1 <- {a} set<char> s2 = s1 + 'b'; // s2 <- {a,b} set<char> s3 = s2 - s1; // s3 <- {b} set<char> s4 = s1 * s2; // s4 <- {a}
Achieving the above results with the existing STL library is by comparison cumbersome, error-prone and unclear.
Although this proposal does not follow the STL design philosophy, it meets a real developer need. It can be implemented using global operator overloads, which should avoid conflicts with other uses of STL sets.
Comments and suggestions welcome.
I guess you and I must be the only two former Pascal programmers hanging around boost. It seems to me that "set of" from Pascal wasn't ever popular with anyone but those who really _really_ used them heavily (e.g. Ada dropped them when it was derived from Pascal). I argued (unsuccessfully) that when the boost::dynamic_bitset<> was proposed that the _least_ we could do would be to fix the mis-characterization of operators <= and >= with regards to sets (for those who haven't studied sets, {b,c,d} <= {a,b,c,d} but that's not how it will evaluate with either std::set or boost::dynamic_bitset). Absent that oddity, I suspect that you could rather easily overload some global operators to handle what you want using any of std::set, std::bitset, or boost::dynamic_bitset (the backwardness of the comparison operators would still bother me, though). Hmmmm, maybe I should look more closely at the "unordered collections" (hash_set) proposal further and see if that correctly manages the set concept.
Best Regards Dominic Herity Red Plain Technology (www.redplain.com) T:+353-87-2208233 F: +1-603-909 6570 E: dominic.herity@redplain.com
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"