Boost logo

Boost :

From: Jim Apple (japple_at_[hidden])
Date: 2003-12-13 23:42:14


New syntax possible:

int choose(int n, int k) {
   function<int (int,int)> choose = memoize(choose);
   if ((k == 0) || (k == n)) {
     return 1;
   } else {
     return choose(n-1,k-1) + choose(n-1,k);
   }
}

"memoize" doesn't have to go through its whole creation and binding
procedure for each recursive call, though, because it is actaully
memoized. It need only look up the answer from previous calls.

I could also build in a third parameter with type memo_p_t, with default
value "memoized." If choose is called as

choose(x,y,no_memo)

the function<int (int,int)> choose is initialized with the int
choose(int,int).

Jim


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