Boost logo

Boost :

From: Hugo Duncan (hugoduncan_at_[hidden])
Date: 2003-10-09 10:07:16


Hi,

I'm looking for the following MPL functionality and wondering if it
already exists somewhere.

I would like to use a runtime index into a typelist to execute a
metafunction (if I've got the terminology correct). At the moment
I can see how to implement this with mpl::for_each, but is there
a better way? Have I missed anything obvious?

ie.

instead of

   int i;
   ...
   switch(i)
   {
     case 0: my_template_fn< mpl::at<my_type_sequence,0> >(); break;
     case 1: my_template_fn< mpl::at<my_type_sequence,1> >(); break;
     case 2: my_template_fn< mpl::at<my_type_sequence,2> >(); break;
   }

I would like to write

   switch<my_type_sequence>(my_metafunction(),i);

or similar.

Hugo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk