[fusion] deduce type of resulting vector from a transformation

Hi, (I keep struggling with Boos.Fusion.) How do I deduce the type of the vector resulting from the transformation of another vector? I have a source vector of different types, e.g. vector<quantity<si::length>, quantity<si::mass>, quantity<si::time>
and I have a transformation that is well defined and returns another type depending on the original type. The question is how do I generate a vector type that is the result of the given transformation. I though that result_of::transform was the function to obtain the result but it turns not because it returns a type transform_view instead of a vector. vector< ... > v1; T? v2(transform(v1, transformation())); i.e. what is the type of T as a fusion::vector as deduced from the type of v1 and the transformation type? -- Thank you, Alfredo-- Below is the illustrative code: #include<boost/array.hpp> #include <boost/fusion/container.hpp> #include <boost/fusion/algorithm/transformation/zip.hpp> #include <boost/units/systems/si.hpp> #include<iostream> using std::clog; using std::endl; using namespace boost::fusion; using namespace boost::units; // this is the transformation struct divide{ template <typename SignatureT> struct result; template<class Q> struct result<divide(Q const&)>{ typedef typename divide_typeof_helper<Q, quantity<si::time> >::type type; }; template<typename Q> typename result<divide(Q const&)>::type operator()(Q const& q) const { return q/quantity<si::time>(1.*si::second); } }; int main(){ typedef vector< quantity<si::length>, quantity<si::mass>, quantity<si::time> > source_type ; source_type v1(1.*si::meter, 2.*si::kilogram, 3.*si::second); clog << "v1: " << at_c<0>(v1) << ", "<< at_c<1>(v1) << ", " << at_c<2>(v1) << endl; // how can I deduce the result_type from the type "divide"? // here manually defined typedef vector< divide_typeof_helper<quantity<si::length>, quantity<si::time>
::type, divide_typeof_helper<quantity<si::mass>, quantity<si::time> ::type, divide_typeof_helper<quantity<si::time>, quantity<si::time> >::type > result_type ;
result_type v2( boost::fusion::transform(v1, divide() ) ); clog << "v2: " << at_c<0>(v2) << ", "<< at_c<1>(v2) << ", " << at_c<2>(v2) << endl; return 0; }

Am 10.10.2010 12:02, schrieb alfC:
Hi,
(I keep struggling with Boos.Fusion.)
How do I deduce the type of the vector resulting from the transformation of another vector?
I have a source vector of different types, e.g. vector<quantity<si::length>, quantity<si::mass>, quantity<si::time>
and I have a transformation that is well defined and returns another type depending on the original type. The question is how do I generate a vector type that is the result of the given transformation. I though that result_of::transform was the function to obtain the result but it turns not because it returns a type transform_view instead of a vector.
vector< ... > v1; T? v2(transform(v1, transformation()));
i.e. what is the type of T as a fusion::vector as deduced from the type of v1 and the transformation type? -- Thank you, Alfredo--
You can generate a vector from an arbitrary fusion sequence using the conversion metafunction: http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/fusion/container/c... fusion::result_of::as_vector< fusion::result_of::transform< v1, transformation >::type
::type v2(fusion::transform(v1, transformation()));
-Christopher

On Oct 10, 3:17 am, Christopher Schmidt <mr.chr.schm...@online.de> wrote:
Am 10.10.2010 12:02, schrieb alfC:
Hi,
(I keep struggling with Boos.Fusion.)
How do I deduce the type of the vector resulting from the transformation of another vector?
I have a source vector of different types, e.g. vector<quantity<si::length>, quantity<si::mass>, quantity<si::time>
and I have a transformation that is well defined and returns another type depending on the original type. The question is how do I generate a vector type that is the result of the given transformation. I though that result_of::transform was the function to obtain the result but it turns not because it returns a type transform_view instead of a vector.
vector< ... > v1; T? v2(transform(v1, transformation()));
i.e. what is the type of T as a fusion::vector as deduced from the type of v1 and the transformation type? -- Thank you, Alfredo--
You can generate a vector from an arbitrary fusion sequence using the conversion metafunction:
http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/fusion/cont...
fusion::result_of::as_vector< fusion::result_of::transform< v1, transformation >::type
::type v2(fusion::transform(v1, transformation()));
Hi, thank you. I tried something like this but I keep getting an error from the compiler. /usr/include/boost/utility/result_of.hpp:68: error: invalid use of incomplete type ‘struct divide::result<divide(boost::un ... what is the problem with the following transformation? that works well as a function but not as metafunction as called from result_of struct divide{ template <typename SignatureT> struct result; template<class Q> struct result<divide(Q const&)>{ typedef typename divide_typeof_helper<Q, quantity<si::time> >::type type; }; template<typename Q> typename result<divide(Q const&)>::type operator()(Q const& q) const { return q/quantity<si::time>(1.*si::second); } }; It works well as a function but not as a metafunction in the following typedef typedef boost::fusion::result_of::as_vector< boost::fusion::result_of::transform< source_type, divide >::type >::type result_type ;

Am 10.10.2010 20:48, schrieb alfC:
On Oct 10, 3:17 am, Christopher Schmidt <mr.chr.schm...@online.de> wrote:
Am 10.10.2010 12:02, schrieb alfC:
Hi,
(I keep struggling with Boos.Fusion.)
How do I deduce the type of the vector resulting from the transformation of another vector?
I have a source vector of different types, e.g. vector<quantity<si::length>, quantity<si::mass>, quantity<si::time>
and I have a transformation that is well defined and returns another type depending on the original type. The question is how do I generate a vector type that is the result of the given transformation. I though that result_of::transform was the function to obtain the result but it turns not because it returns a type transform_view instead of a vector.
vector< ... > v1; T? v2(transform(v1, transformation()));
i.e. what is the type of T as a fusion::vector as deduced from the type of v1 and the transformation type? -- Thank you, Alfredo--
You can generate a vector from an arbitrary fusion sequence using the conversion metafunction:
http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/fusion/cont...
fusion::result_of::as_vector< fusion::result_of::transform< v1, transformation >::type
::type v2(fusion::transform(v1, transformation()));
Hi, thank you. I tried something like this but I keep getting an error from the compiler.
/usr/include/boost/utility/result_of.hpp:68: error: invalid use of incomplete type ‘struct divide::result<divide(boost::un ...
what is the problem with the following transformation? that works well as a function but not as metafunction as called from result_of
struct divide{ template <typename SignatureT> struct result; template<class Q> struct result<divide(Q const&)>{ typedef typename divide_typeof_helper<Q, quantity<si::time> >::type type; }; template<typename Q> typename result<divide(Q const&)>::type operator()(Q const& q) const { return q/quantity<si::time>(1.*si::second); } };
It works well as a function but not as a metafunction in the following typedef
typedef boost::fusion::result_of::as_vector< boost::fusion::result_of::transform< source_type, divide >::type >::type result_type ;
Try const-qualifying source_type in fusion::result_of::transform<...> or add a specialization for a non-const reference argument type in divide::result. (fusion::transform just accepts a reference to a const-qualified sequence whereas fusion::result_of::transform does not care about const-qualification at all and passes the template parameter types right down to the fusion::transform_view .) -Christopher

On Sun, Oct 10, 2010 at 12:09 PM, Christopher Schmidt <mr.chr.schmidt@online.de> wrote:
Am 10.10.2010 20:48, schrieb alfC:
On Oct 10, 3:17 am, Christopher Schmidt <mr.chr.schm...@online.de> wrote:
Am 10.10.2010 12:02, schrieb alfC:
Hi,
(I keep struggling with Boos.Fusion.)
How do I deduce the type of the vector resulting from the transformation of another vector?
I have a source vector of different types, e.g. vector<quantity<si::length>, quantity<si::mass>, quantity<si::time>
and I have a transformation that is well defined and returns another type depending on the original type. The question is how do I generate a vector type that is the result of the given transformation. I though that result_of::transform was the function to obtain the result but it turns not because it returns a type transform_view instead of a vector.
vector< ... > v1; T? v2(transform(v1, transformation()));
i.e. what is the type of T as a fusion::vector as deduced from the type of v1 and the transformation type? -- Thank you, Alfredo--
You can generate a vector from an arbitrary fusion sequence using the conversion metafunction:
http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/fusion/cont...
fusion::result_of::as_vector< fusion::result_of::transform< v1, transformation >::type
::type v2(fusion::transform(v1, transformation()));
Hi, thank you. I tried something like this but I keep getting an error from the compiler.
/usr/include/boost/utility/result_of.hpp:68: error: invalid use of incomplete type ‘struct divide::result<divide(boost::un ...
what is the problem with the following transformation? that works well as a function but not as metafunction as called from result_of
struct divide{ template <typename SignatureT> struct result; template<class Q> struct result<divide(Q const&)>{ typedef typename divide_typeof_helper<Q, quantity<si::time> >::type type; }; template<typename Q> typename result<divide(Q const&)>::type operator()(Q const& q) const { return q/quantity<si::time>(1.*si::second); } };
It works well as a function but not as a metafunction in the following typedef
typedef boost::fusion::result_of::as_vector< boost::fusion::result_of::transform< source_type, divide >::type >::type result_type ;
Try const-qualifying source_type in fusion::result_of::transform<...> or add a specialization for a non-const reference argument type in divide::result. (fusion::transform just accepts a reference to a const-qualified sequence whereas fusion::result_of::transform does not care about const-qualification at all and passes the template parameter types right down to the fusion::transform_view .)
Yes, I just realized that something like that worked, a bunch of remove_const and remove_reference worked. Is there a way to simplify this? struct divide{ template <typename SignatureT> struct result; template<class Q> struct result<divide(Q)>{ typedef typename divide_typeof_helper< typename boost::remove_const< typename boost::remove_reference< Q >::type >::type, quantity<si::time> >::type type; }; template<typename Q> typename result<divide(Q)>::type operator()(Q q) const { return typename result<divide(Q)>::type(); //return q/quantity<si::time>(1.*si::second); } }; Thanks, Alfredo
participants (3)
-
alfC
-
Alfredo Correa
-
Christopher Schmidt