Boost logo

Boost Users :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-01-21 19:06:29


AMDG

cp now wrote:
> Hello.
>
> I am trying to instantiate a template taking two parameters across a
> series of types contained in mpl::vector's, and place the resulting
> types in an mpl::vector.
>
> template <class A, class B> class T {};
> typedef mpl::vector<int, double, char> Atypes;
> typedef mpl::vector<double, std::string> Btypes;
>
> template <template <class, class> class TEMPLATE,
> class ATYPE,
> class BTYPES,
> class CLASSES>
> struct unary_fold_inner : mpl::fold<
> BTYPES,
> CLASSES,
> mpl::push_back<mpl::_1, TEMPLATE<ATYPE, mpl::_2> >
> > {};
>
> template <template <class, class> class TEMPLATE,
> class ATYPES,
> class BTYPES>
> struct unary_fold : mpl::fold<
> ATYPES,
> mpl::vector<>,
> typename detail::unary_fold_inner<TEMPLATE, mpl::_2, BTYPES,
> mpl::_1>::type
> > {};

Problem #1. This causes the metafunction unary_inner_fold to be
evaluated immediately.
Don't put ::type here. You want unary_inner_fold to be evaluated by
mpl::fold.

Problem #2
MPL Lambda can't handle template template arguments. Use a metafunction
class instead.

>
> typedef unary_fold<
> T,
> Atypes,
> Btypes
> >::type CLASSES;

The following gives the correct answers for me:

#include <string>

#include <boost/mpl/vector.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/quote.hpp>

namespace mpl = boost::mpl;

template <class A, class B> class T {};
typedef mpl::vector<int, double, char> Atypes;
typedef mpl::vector<double, std::string> Btypes;

template <class TEMPLATE,
   class ATYPE,
   class BTYPES,
   class CLASSES>
struct unary_fold_inner : mpl::fold<
   BTYPES,
   CLASSES,
   mpl::push_back<mpl::_1, mpl::apply2<TEMPLATE, ATYPE, mpl::_2> >
> {};

template <class TEMPLATE,
   class ATYPES,
   class BTYPES>
struct unary_fold : mpl::fold<
   ATYPES,
   mpl::vector<>,
   typename unary_fold_inner<TEMPLATE, mpl::_2, BTYPES, mpl::_1>
> {};

//typedef CLASSES;

template<class Message>
struct print {};

typedef print<
    unary_fold<
        mpl::quote2<T>,
       Atypes,
       Btypes
>::type
>::type CLASSES;

In Christ,
Steven Watanabe


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