Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2003-11-09 20:46:52


> Matthias Schabel wrote:
> > How does one implement append? That is, given
> >
> > typedef mpl::list<t1,t2,t3> l1;
> > typedef mpl::list<t4,t5> l2;
> >
> > typedef append<l1,l2> --> mpl::list<t1,t2,t3,t4,t5>
> >
> > I've tried things like
> >
> > typedef typename mpl::iter_fold<S2,S1,push_back<_1,deref<_2> >
> >::type a;
>
> template<class Seq1, class Seq2>
> struct append
> : mpl::insert_range<
> Seq1
> , typename mpl::end<Seq1> ::type
> , Seq2
> >
> {};
>
> --
> Daniel Wallin

Should the following code compile? I think so, based on your
suggestion, but gcc 3.3 fails (I'm running on
Mac OS 10.3) at the static assert...

#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>

#include <boost/mpl/equal.hpp>
#include <boost/mpl/insert_range.hpp>
#include <boost/mpl/list.hpp>

struct t1 { };
struct t2 { };
struct t3 { };
struct t4 { };

template<class S1,class S2>
struct append :
        public boost::mpl::insert_range<S1,boost::mpl::end<S1>,S2>
{ };

int main()
{
        typedef boost::mpl::list<t1,t2,t3,t4> l1;
        typedef boost::mpl::list<t4,t3,t2,t1> l2;

        typedef append<l1,l2>::type ap1;
        
        typedef boost::mpl::list<t1,t2,t3,t4,t4,t3,t2,t1> l3;
        
        typedef boost::mpl::equal<ap1,l3>::type b1;
        
        BOOST_STATIC_ASSERT((boost::is_same<b1,boost::mpl::true_>::value ==
true));
                                  
        return 0;
}

------------------------------------------------------------------------
---------------------------
Matthias Schabel, Ph.D.
Utah Center for Advanced Imaging Research
729 Arapeen Drive
Salt Lake City, UT 84108
801-587-9413 (work)
801-585-3592 (fax)
801-706-5760 (cell)
801-484-0811 (home)
mschabel at ucair med utah edu


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk