Creating a set of sets of <X> is possible, since operator < is already overloaded within STL's set class. (So please don't write an example program showing me it is possible). I'm trying to find out if this is a reliable container for a large scale program (you'll understand why later on). As far as I know, STL's set inserts the elements in a tree, according to it's key.
Mathemathically speaking, given two sets A and B, one, and only one of the following situations will happen A=B (every a from A is in B, and every b of B is in A) or A != B (At least one a from A is not in B or vice-versa). It makes no sense saying A<B or B<A (The closest thing you can say |A|<|B|, where |A|, and |B| represents the ammount of elements in A, and in B, respectively). That's why a tree implementation for a set of sets is mathematically absurd (you wouldn't make advantage of the tree. I'll explain this later on).
However, it's still possible to overload the operator < for sets and yet, make some sense. For instance:
1 2 3
|
bool operator < (const set<KEY>& a,const set<KEY>& a) const{
return (a != b);
}
|
Remember this implementation, since we'll use it later on.
Since STL's set uses a tree implementation of the data, this would only work correctly if comparisons within the insertions, searches and deletions are done in the same order (for example, "searched key" is compared to the "actual-tree"'s key (Actual = Searched, actual and searched are sets). If not found yet, we go to the "left sub-tree" (if Actual != Searched then //go to left sub tree). If not found yet, we go to the "right sub-tree"( Actual != Searched -> This situation will never happen).
If this works, we would have a list of sets, which works pretty much allright. The problem comes here: If set's data tree is rebalanced after each insertion, we'll lose permanently the access to several sets of data, due to the nature of the operator < overload.
That's why I am asking: Is it a good idea to use set < set <KEY> > in a large scale program?