[fusion] Introspection of fused objects?

Suppose I have a function object created on the basis of a sequence of fused function objects, where I would like to do shuffle the call order on the basis of some criterion. template< typename SeqOfFused > struct merge_fused { merge_fused( SeqOfFused f ): m_functions( f ) {} typedef void result_type; template< int N, typename Seq > void operator()( Seq& seq ) { // normal dispatch call would be fusion::at_c<N>(m_functions)( seq ); if ( some case ) { store seq for later use } else { call appropriate fused object with parts of stored stuff } } SeqofFused m_functions; // some state / memory specific to this group of fused objects some_state m_state; }; I'm doing a static cast to a superclass to get rid of the int N template parameter, to make the merge_fused look exactly like a fused function object. This works fine. Storing stuff is what my question is about: is there any way to know the type of Seq from its Fused counterpart? Looking at the code, the answer is no, but perhaps there exists introspection code in fusion which I am unaware of? One solution would be to simply use static casting based on Seq in operator(), but then my question would be: is that safe? Thanks, Rutger

AMDG Rutger ter Borg wrote:
Suppose I have a function object created on the basis of a sequence of fused function objects, where I would like to do shuffle the call order on the basis of some criterion.
template< typename SeqOfFused > struct merge_fused {
merge_fused( SeqOfFused f ): m_functions( f ) {}
typedef void result_type;
template< int N, typename Seq > void operator()( Seq& seq ) {
// normal dispatch call would be fusion::at_c<N>(m_functions)( seq );
if ( some case ) { store seq for later use } else { call appropriate fused object with parts of stored stuff } }
SeqofFused m_functions;
// some state / memory specific to this group of fused objects some_state m_state; };
I'm doing a static cast to a superclass to get rid of the int N template parameter, to make the merge_fused look exactly like a fused function object. This works fine.
What are you casting to a superclass?
Storing stuff is what my question is about: is there any way to know the type of Seq from its Fused counterpart? Looking at the code, the answer is no, but perhaps there exists introspection code in fusion which I am unaware of?
What is the "Fused Counterpart" of Seq.
One solution would be to simply use static casting based on Seq in operator(), but then my question would be: is that safe?
Is Seq always that same type? It sounds dangerous, but I don't really understand what you want to do. In Christ, Steven Watanabe

Steven Watanabe wrote:
What are you casting to a superclass?
The functor merge_fused above is not a proper fused function object. In this case, I did a template< typename Base, int N > struct select: Base { template< typename Seq > void operator()( Seq& seq ) { Base::template operator()<N>(seq); } } to make N proper fused function objects. Although it is a nice trick, I guess this was not my real question.
What is the "Fused Counterpart" of Seq.
This is more in the direction of the real question :-) .. The question is, I guess, if you do g = make_fused( f ) then, are the parameter types of f still available in g somehow?
Is Seq always that same type?
No, it is not, and I suspect it is just the sequence type passed by the user. To make it all safe (and, if I'm going to use this approach), I guess I neeed to pass more type information myself. Thanks, Cheers, Rutger

AMDG Rutger ter Borg wrote:
Is Seq always that same type?
No, it is not, and I suspect it is just the sequence type passed by the user. To make it all safe (and, if I'm going to use this approach), I guess I neeed to pass more type information myself.
Does this help:
boost::function
participants (2)
-
Rutger ter Borg
-
Steven Watanabe