Boost logo

Boost Users :

From: Alan M. Carroll (amc_at_[hidden])
Date: 2005-08-26 13:51:45

I think you should be able to do something computationally equivalent. I'd try for a variant of tail recursion where you have a complex_functor that does something like

complicated_function< mpl::front<L>::type > (i);
mpl::if size<L> > 1
        complicated_functor< mpl::pop_front<L>::type > (i);
Then you invoke this instead of the "for" loop. I haven't looked too closely but mpl::fold might already do this kind of thing.

At 11:21 AM 8/26/2005, you wrote:
>I would like to be able to write code like this:
> int i;
> for F in LIST_OF_TYPES
> complicated_function<F>(i);
>where this code is inside some other function which is inside a class
>templatized over LIST_OF_TYPES. Given the lack of nested functions and
>classes in C++ functions, am I correct in thinking that it's impossible
>to do this sort of thing inside another function?
>In my particlar case, all the complicated code has already been factored
>into complicated_function, and there are only ever two LISTS_OF_TYPES, so
>my current solution is just to manually specialize over LISTS_OF_TYPES.
>However, this kind of construct often appears several times (with different
>complicated_functions) in a given outer function, so it would be very nice
>to only have to write down the high level structure once.
>Boost-users mailing list

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at