|
Boost Users : |
Subject: [Boost-users] some difficulty with transform_view
From: e r (erwann.rogard_at_[hidden])
Date: 2008-09-13 22:34:32
Steven Watanabe wrote:
> AMDG
>
> e r wrote:
>> I may have made a little bit of progress here...
>>
>>
>> template<typename A>
>> struct result<fun(const A&)>{
>> typedef A type;
>> };
>>
>
> Yeah. That's the idea. I generally use function_traits rather than
> partial specialization. In your original example (untested):
>
> #include <boost/type_traits/function_traits.hpp>
> #include <boost/type_traits/remove_cv.hpp>
> #include <boost/type_traits/remove_refence.hpp>
>
> struct fun {
> template<class Sig>
> struct result {
> typedef typename boost::function_traits<Sig>::arg1_type arg1_type;
> typedef typename boost::function_traits<Sig>::arg2_type arg2_type;
> typedef typename boost::remove_cv<typename
> boost::remove_reference<arg1_type>::type>::type Metafun;
> typedef typename Metafun::type type;
> };
> // ...
> }
>
> In Christ,
> Steven Watanabe
Much appreciated, thanks! made changes as suggested and works.
but i can't get this simple algorithm to work (errors shown in the code
below). please help.
algorithm:
map fusion::vector<A,B,C,...> to
fusion::vector<identity<A>,identity<B>,identity<C>,...>
and call {identity<X>::type(arg):X=A,B,C,...} via transform. use the
result to copy construct fusion::vector<A,B,C,...>.
*.cpp
typedef boost::fusion::vector2<boost::mpl::int_<0>,boost::mpl::int_<1> >
vec1_type;
typedef boost::range<vec1_type> range_type;
range_type::result::type result( range_type::create() );
vec1_type vec1 = result; // error: no matching function for call to
boost::fusion::vector_data2<boost::fusion::vector2<mpl_::int_<0>,
mpl_::int_<1> >, mpl_::int_<0>, mpl_::int_<1> >::vector_data2(const
boost::mpl::identity<mpl_::int_<0> >, const
boost::mpl::identity<mpl_::int_<1> >)|
*.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,apply_wrapper<metafun> >::type type;
};
struct range_fun{
range_fun(){}
template<class Signature>
struct result {
typedef boost::function_traits<Signature> fun_traits;
typedef typename fun_traits::arg1_type arg1_type;
typedef typename boost::remove_cv<
typename boost::remove_reference<arg1_type> >::type metafun_type;
typedef typename metafun_type::type type;
};
template<typename Metafun> typename Metafun::type operator()(const
Metafun& meta)const{
typedef typename Metafun::type result_type;
return result_type(); //for now arg2 ommitted for simplicity
}
};
template<typename Result>
struct range{
typedef typename apply_wrapper_to_seq<Result>::type wrappers_type;
struct result{
typedef typename fusion::result_of::transform<
const wrappers_type,range_fun>::type type;
}; //ommitting const causes compile error
static typename result::type create(){
typedef range_fun f_type;
BOOST_MPL_ASSERT((mpl::equal<Result,typename
result::type>));//mpl_::failed (see below)
return fusion::transform(wrappers_type(),f_type());
}
};
no matching function for call to
assertion_failed(mpl_::failed************
boost::mpl::equal<boost::fusion::vector2<mpl_::int_<0>, mpl_::int_<1> >,
boost::fusion::transform_view<const
boost::fusion::vector<boost::mpl::identity<mpl_::int_<0> >,
boost::mpl::identity<mpl_::int_<1> >, boost::fusion::void_,
boost::fusion::void_, boost::fusion::void_, boost::fusion::void_,
boost::fusion::void_, boost::fusion::void_, boost::fusion::void_,
boost::fusion::void_>, boost::range_fun, boost::fusion::void_>,
boost::is_same<mpl_::arg<-0x00000000000000001>,
mpl_::arg<-0x00000000000000001> > >::************)|
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