
On 07/10/10 08:57, Larry Evans wrote:
On 07/08/10 19:42, John Dlugosz wrote:
So you give it two functions, one to do on the way down and another to do on a the way up? Yes. However, I'm not sure if the way-up function is the NowUp or Else template parameter. I'd have to look at the backus_turingaward_lecture.pdf reference to see which is which.
[snip] Anyway, the attached fusion::if_recur does what I was thinking as a solution. The test driver is also attached with the output. The test driver uses:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/iostreams/ut...
[snip] A revised version of this code is now in: http://svn.boost.org/svn/boost/sandbox/variadic_templates/ boost/fusion/algorithm/if_recur.hpp libs/fusion/sandbox/if_recur.cpp The compilation and run output is in the attachment. The indentation provided by indent_scoped_ostreambuf shows the recursion depth pretty clearly. The if_recur template has another template parameter, the last one, which governs whether the recursion is terminated on values or types. The recursion termination on types was *much* harder to implement. I'm wondering if going up the recursion stack wouldn't be faster if an explicit stack were used instead of the way it's done in if_recur. A nice side effect of the explicit stack is the ability to short-circuit the recursion as soon as a termination condition is met. In contrast, with the example in if_recur.cpp, the stack, since its implicit, must be unwound completely, while a flag is used to tell the template functions, specifically, the iter_find_target<*>::now_up<*>::call, that the answer is already found. In the example, that flag is simply that IterUp is not the same as IterEnd. Anyway, HTH. -regards, Larry ###-*- mode: compilation; default-directory: "~/prog_dev/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/" -*- Compilation started at Sun Jul 18 10:54:13 make run install -d `dirname /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.o` /home/evansl/download/stlfilt/gfilt -compiler:/home/evansl/download/gcc/4.5-20100624/install/bin/g++ -c -Wall -ftemplate-depth-300 -O0 -g3 -fno-inline -std=gnu++0x -DCXX0X_VARIADIC_TEMPLATES -I/home/evansl/prog_dev/boost-svn/ro/sandbox/rw/variadic_templates -I/home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/lje -I/home/evansl/prog_dev/boost-svn/ro/trunk -DTEMPLATE_DEPTH=300 if_recur.cpp -MMD -o /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.o COMPILE.cmd=/home/evansl/download/gcc/4.5-20100624/install/bin/g++ -c -Wall -ftemplate-depth-300 -O0 -g3 -fno-inline -std=gnu++0x -DCXX0X_VARIADIC_TEMPLATES -I/home/evansl/prog_dev/boost-svn/ro/sandbox/rw/variadic_templates -I/home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/lje -I/home/evansl/prog_dev/boost-svn/ro/trunk -DTEMPLATE_DEPTH=300 if_recur.cpp -MMD -o /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.o BD Software STL Message Decryptor v3.10 for gcc 2/3/4 sed -e 's#^if_recur.o:#/home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.o:#' /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.d> /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.o.dep #rm /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.d /home/evansl/download/gcc/4.5-20100624/install/bin/g++ -Wl,-rpath /home/evansl/download/gcc/4.5-20100624/install/lib64 /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.o -o /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.exe /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5v/boost-svn/ro/sandbox/rw/variadic_templates/libs/fusion/sandbox/if_recur.exe list_v=[int_val<-9>(-9), int_val<0>(0), int_val<-9>(-9), int_val<2>(2)] target_v=int_val<-9>(-9) iter_next: iter_now=int_val<-9>(-9) int_val<0>(0) int_val<-9>(-9) int_val<2>(2) iter_next: iter_now=int_val<0>(0) int_val<-9>(-9) int_val<2>(2) iter_next: iter_now=int_val<-9>(-9) int_val<2>(2) iter_next: iter_now=int_val<2>(2) iter_btm: iter_now= now_up: iter_now=int_val<2>(2) iter_up= now_up: iter_now=int_val<-9>(-9) int_val<2>(2) iter_up= now_up: iter_now=int_val<0>(0) int_val<-9>(-9) int_val<2>(2) iter_up=int_val<-9>(-9) int_val<2>(2) now_up: iter_now=int_val<-9>(-9) int_val<0>(0) int_val<-9>(-9) int_val<2>(2) iter_up=int_val<-9>(-9) int_val<2>(2) result_v=int_val<-9>(-9) int_val<2>(2) Compilation finished at Sun Jul 18 10:54:19