Boost logo

Boost Users :

Subject: [Boost-users] fusion::result_of::transform<Seq1,Seq2,F>
From: e r (erwann.rogard_at_[hidden])
Date: 2008-09-10 23:48:25


hello,

here's what I'm trying to do:

*.cpp

//result_type() not valid
typedef fusion::vector<A,B,C> result_type;
//arg2s_type() is valid
typedef fusion::vector<Arg2A,Arg2B,Arg2C> arg2s_type;

//transforms
// (fusion::vector<identity<A>,identity<B>,identity<C> >(),arg2s_type())
// into {A(arg1,Arg2A()),B(arg1,Arg2B()),C(arg1,Arg2C()))}
result_type result(
  range<result_type,args2_type>::create(
        arg1 //arbitrary type Arg1
  )
);

here's my attempt. problems/questions are shown in comments.

*.hpp:

template<template<typename> class metafun = mpl::identity>
struct apply_wrapper{
        template<typename T>
        struct apply{
            typedef metafun<T> type;
        };
};
template<typename Seq,template<typename> class metafun = mpl::identity>
struct apply_wrapper_to_seq{
  typedef typename mpl::transform<
    Seq, // e.g. fusion::vector<A,B,C>
    apply_wrapper<metafun>
>::type type;
//e.g. fusion::vector<identity<A>,identity<B>,identity<C> >
};

template<typename Arg1>
struct fun{
  fun(const Arg1& args):args_(args_){}
  //copy, assign...

// probably not what result_of::transform expects, based on compile
// errors (below)
  template<typename Metafun,typename Arg2>
  struct result{
     typedef typename Metafun::type type;
  };

  template<typename Metafun,typename Arg2>
  typename Metafun::type //e.g Metafun = identity<A>
  operator()(const Metafun& meta,const Arg2& arg2)const{
      typedef typename Metafun::type result_type; //e.g. A
      return result_type(args,arg2);
  }
    const Arg1& args_;
};

template<typename Result,typename Arg2s>
struct range{
 //e.g. fusion<identity<A>,identity<B>,identity<C> >
 typedef typename apply_wrapper_to_seq<Result>::type wrappers_type;
 //e.g. fusion::vector<Arg2A,Arg2B,Arg2C>
 typedef Arg2s arg2s_type;

 template<typename Arg1>
 struct result{
   typedef typename fusion::result_of::transform<
       wrappers_type,
       arg2s_type,
       fun<Arg1>
>::type type;
 };

 template<typename Arg1>
 static typename result<Arg1>::type create(const Arg1& args){
   typedef fun<Arg1> f_type;
   wrappers_type wrappers;
   arg2s_type arg2s;
   f_type f(args);

   BOOST_MPL_ASSERT(
    (
      mpl::equal<
        Result,
        typename result<Arg1>::type
>
    )
  );//result_of::fun causes compile error
/usr/local/boost_1_35_0/boost/utility/result_of.hpp|34|instantiated from
‘boost::detail::result_of_impl<
factory::fun<Arg1>, factory::fun<Arg1> > ()(boost::mpl::identity<A>,
Arg2A), false>’|
...
//usr/local/boost_1_35_0/boost/utility/result_of.hpp|68|error: wrong
number of template arguments (1, should be 2)|
//factory/range.hpp|32|error: provided for ‘template<class Arg1>
template<class Metafun, class Arg2> struct factory::fun<Arg1>::result’|
//usr/local/boost_1_35_0/boost/fusion/view/transform_view/detail/value_of_impl.hpp|55|error:
no type named ‘type’ in ‘struct
//boost::mpl::apply<boost::fusion::detail::apply_transform_result<factory::fun<Arg1>,
boost::mpl::identity<A>, Arg2A, mpl_::na, mpl_::na, mpl_::na>’|

  return fusion::transform(
       wrappers,
       arg2s,
       f
  );
 }
};

any help would appreciated. thanks!


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