Boost logo

Boost Users :

From: Scott Meyers (usenet_at_[hidden])
Date: 2008-02-22 13:47:52


I have a set of types representing features code might have, e.g.,

   typedef mpl::vector<ExceptionSafe, ThreadSafe, ReallyFast, GPLed> Features;

These can occur in any combination as sets of features, e.g.,

   tyepdef FeatureSet<ExceptionSafe> F1;
   typedef FeatureSet<ThreadSafe, ExceptionSafe> F2;
   typedef FeatureSet<ReallyFast, ExceptionSafe, GPLed> 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<ExceptionSafe, ThreadSafe, ReallyFast, GPLed>

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<ExceptionSafe, ThreadSafe>
up from FeatureSet<ExceptionSafe, ReallyFast>
leaves: FeatureSet<ExceptionSafe, GPLed>
               ...

The next level up (which is one below the root) is triplets of features:

One level FeatureSet<ExceptionSafe, ThreadSafe, ReallyFast>
down from FeatureSet<ExceptionSafe, ThreadSafe, GPLed>
root: FeatureSet<ExceptionSafe, ReallyFast, GPLed>
               ...

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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net