[fusion] runtime unsigned to a template argument compile-time unsigned

Hi, I have a struct adapted as a fusion sequence. My user inputs at runtime the index of the member she is interested in. Assuming all members are convertible to double, the only solution I found so far is: double f(unsigned index) { switch(index) { case 0: return boost::fusion::at_c<0>( sequence ); case 1: return boost::fusion::at_c<1>( sequence ); . case 6: return boost::fusion::at_c<6>( sequence ); } } To generate this: 1. 0 to fusion::result_of::size<Seq>::type::value - 1 is the range I want. 2. I can't use PP to generate the cases inside the switch 3. Can I generate an array of function pointers to the various at<>() functions and call the right one at runtime? I am basically looking for the runtime version of at_c. Regards,

On 02/21/10 05:27, Hicham Mouline wrote: [snip]
3. Can I generate an array of function pointers to the various at<>() functions and call the right one at runtime?
The 2 attached files show how this can be done. Obviously, instead of: typedef void(* method_type )(void) ; you'd have: typedef double(* method_type )(void) ; HTH. -regards, Larry

On 02/22/10 10:02, Larry Evans wrote:
On 02/21/10 05:27, Hicham Mouline wrote: [snip]
3. Can I generate an array of function pointers to the various at<>() functions and call the right one at runtime?
The 2 attached files show how this can be done.
Obviously, instead of:
typedef void(* method_type )(void) ;
you'd have:
typedef double(* method_type )(void) ;
This could even be done for heterogeneous return types; however, in that case, a tagged variant. The tag for this variant would be the field index. In the attached code, this would be something like the super_numerals.
participants (2)
-
Hicham Mouline
-
Larry Evans