Boost logo

Boost :

From: Ashot Nakashian (AshotN_at_[hidden])
Date: 2002-08-12 07:36:44

Quoting j.adelman_at_[hidden] <j.adelman_at_[hidden]>:

>For recursion, it's surely far more sane to use
>something like the following:
>struct factorial
> int current,max,total; // Imagine this is some
>*big* data
> operator int(){return total;}
> factorial(int x):current(1),max(x),total(1){}
> void recurse()
> {
> total*=current++;
> if(current<=max) recurse();
> return;
> }
>int main()
> return factorial(5);

Well, I agree, it's neat albeit limited. I'm thinking of a more
"universal solution for huge static-objects that are destructible"
whenever they are no longer needed, rather than "solutions for recursive
functions"! Your solution holds true for simple applications and, of
course, for self-contained functions (like the above example). But what
about complex structures, what about recursive class-member-functions
that access other object's data, as well as their own, while utilizing
some other static ones? Would creating an object, copying the data in,
calling the recursive function, then copying back the results be a
better solution compared to an object that emulates the static behavior
needed? I don't think so.

I'm working on a compiler for an assembly language, and the language
parser has a few functions where such destructible static-objects are
the perfect solution. I want to take the idea to a higher level, a more
reusable one.


Boost list run by bdawes at, gregod at, cpdaniel at, john at