Boost logo

Boost Users :

Subject: [Boost-users] [fusion] runtime unsigned to a template argument compile-time unsigned
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-02-21 06:27:28


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,

 



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