[mpl] Combining Type Sequences
Giving the following code:
#include
"Eric Lemings"
Giving the following code:
#include
namespace mpl = boost::mpl; template < unsigned U, int I = 1 > struct T : mpl::integral_c< unsigned, U > { BOOST_STATIC_CONST(int, N = I); }; and two vectors of type T of varying lengths:
typedef mpl::vector < T<0>, T<1>, T<2> > t1; typedef mpl::vector < T<2, 2>, T<0, 0> > t2;
How would you create a joint view of t1 and t2, sorted by increasing U values, where all elements of t1 and t2 that have the same U value have their N constants added together.
In the example above, the resulting type t0 would be equivalent to:
typedef mpl::vector < T<0, 1>, T<1, 1>, T<2, 3> > t0;
You wouldn't. A view is not the right tool for this job, since the underlying vectors don't contain all the elements of the result, and especially not a joint_view, since that merely concatenates two sequences. I would sort each vector using mpl::sort and then use a compile-time algorithm similar to std::set_intersection to merge them. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Eric Lemings