Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-01-08 21:39:45

Slawomir Lisznianski <public_at_[hidden]> writes:

> Hello,
> I'm trying to find a solution to the following problem. Given types A, B
> and C such that C is derived from B and B is derived from A, and a
> sequence S1 which stores A, B and C (in arbitrary order):
> 1) transform S1 so resulting sequence S2 would have elements sorted
> according to their relative position within their inheritance hierarchy
> (say, most derived first).
> 2) when one introduces another type, D, which doesn't inherit from any
> of A, B or C, after sorting S1, it would end up at the end of S2.
> 3) the solution needs to be unintrusive for the "input" types, that is,
> it ought to work for existing types.

If it weren't for requirement #2, you could use

   mpl::sort<S1, is_base_and_derived<_,_> >::type

But for the purposes of your use case below, I don't see why you need
requirement #2. It seems to me that D could appear at any position
without disrupting the way it works.

> Purpose
> -------
> By finding a way to sort S1 according to predicates listed above, I hope
> to come up with a generic exception-handling mechanism (used in RPC-like
> library), example:
> typedef vector<E0, E1, .. ,En> sorted_exception_decl;
> try
> {
> func();
> }
> catch(at<sorted_exception_decl, int_<0> >::value const & E0)
> { .. }
> catch(at<sorted_exception_decl, int_<1> >::value const & E1)
> { .. }
> catch(at<sorted_exception_decl, int_<n> >::value const & En)
> { .. }

Dave Abrahams
Boost Consulting

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at