[fusion] transform and transform_view
Hi,
I have a small functor:
struct operation {
template<class> struct result;
template< class F >
struct result
On 4/22/2011 8:47 PM, Karsten Ahnert wrote:
Hi,
I have a small functor:
struct operation { template<class> struct result;
template< class F> struct result
{ typedef long type; }; template< class F> struct result
{ typedef double type; }; template< class T> typename result< operation(T)>::type operator()( T t ) { typedef typename result< operation(T)>::type result_type; return result_type( t * T( 2 ) ); } };
and I wonder why a transform_view works as expected:
typedef fusion::vector< int , float> vector_type; vector_type v( 1 , 3.4 ); fusion::transform_view< vector_type , operation> tv( v , operation() );
while
result_of::transform does not:
fusion::result_of::transform< vector_type , operation>::type tv2 = fusion::transform( v , operation() );
result in compile errors? Any hints?
Try: fusion::result_of::transform< vector_type const, operation >::type tv2 = fusion::transform( v , operation() ); Notice the const. As of now, Fusion many algos accept only const sequences. There's a rationale why: Fusion algos are basically non-mutating and returns views. Anyway, I intend to relax this restriction and accept non-const sequences soon. Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com
Try:
fusion::result_of::transform< vector_type const, operation >::type tv2 = fusion::transform( v , operation() );
Notice the const. As of now, Fusion many algos accept only const sequences. There's a rationale why: Fusion algos are basically non-mutating and returns views. Anyway, I intend to relax this restriction and accept non-const sequences soon.
Regards,
Thank you, it works. Is there a simple way to do a non-lazy transform?
On 4/22/2011 9:06 PM, Karsten Ahnert wrote:
Try:
fusion::result_of::transform< vector_type const, operation>::type tv2 = fusion::transform( v , operation() );
Notice the const. As of now, Fusion many algos accept only const sequences. There's a rationale why: Fusion algos are basically non-mutating and returns views. Anyway, I intend to relax this restriction and accept non-const sequences soon.
Regards,
Thank you, it works. Is there a simple way to do a non-lazy transform?
Just assign it back to the vector: typedef fusion::vector< int , float> vector_type; vector_type v( 1 , 3.4 ); v = fusion::transform( v , operation() ); Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com
participants (2)
-
Joel de Guzman
-
Karsten Ahnert