[MPL] sorting sequence according to inheritance hierarchy
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.
Example
-------
Input:
S1 = { A, C, D, B };
Expected result, after sorting:
S2 = { C, B, A, D };
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
Slawomir Lisznianski
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
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
sorted_exception_decl; try { func(); } catch(at
>::value const & E0) { .. } catch(at >::value const & E1) { .. } catch(at ::value const & En) { .. }
-- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams wrote:
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.
duh :-) Thanks! -- Slawomir Lisznianski Paramay Group, LLC "Programs for Research Machinery"
participants (2)
-
David Abrahams
-
Slawomir Lisznianski