I have a set of types representing features code might have, e.g.,
typedef mpl::vector Features;
These can occur in any combination as sets of features, e.g.,
tyepdef FeatureSet<ExceptionSafe> F1;
typedef FeatureSet F2;
typedef FeatureSet F3;
There should be an implicit conversion from one FeatureSet to another if and
only if we don't lose any features in the conversion. So converting from F1 to
F2 or F3 is okay (since both F2 and F3 contain ExceptionSafe), but converting
from F2 to F3 is not okay (because we'd lose ThreadSafe). Furthermore, a
conversion that adds fewer features is preferable to one that adds more, so the
conversion from F1 to F2 is better than the conversion from F1 to F3 (because
the former adds only one feature while the latter adds two).
I'm looking for a way to automatically generate an inheritance hierarchy that
will give me the behavior I've described. For the above example, the hierarchy
has four levels. The root is all the features, because any subset of features
is permitted to be implicitly convertible to the set of all features.
Root: FeatureSet
The leaves are the individual features:
Leaves: FeatureSet<ExceptionSafe>
FeatureSet<ThreadSafe>
FeatureSet<ReallyFast>
FeatureSet<GPLed>
The next level up is pairs of features:
One level FeatureSet
up from FeatureSet
leaves: FeatureSet
...
The next level up (which is one below the root) is triplets of features:
One level FeatureSet
down from FeatureSet
root: FeatureSet
...
In general, given a list of n features, I need a hierarchy n levels deep, with
one class at the root, n classes at the leaves, and m-wise combinations of the n
features at the intervening levels (where m varies from 2 to n-1).
Fortunately, I don't need to worry about permutations of the ordering of the
features, because I already have a way to canonically order them. (Not a great
way, but it works, and that's a different problem.)
Is there some way for me to use the MPL to automatically generate the hierarchy
I need?
Thanks,
Scott