Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-07-22 08:18:11


"Eric Lemings" <lemings_at_[hidden]> writes:

>
> Giving the following code:
>
> #include <boost/mpl/integral_c.hpp>
> 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

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