Re: c++ function templates and memory hogging

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mojmir Svoboda schreef:
i do not attempt to answer your problem, but i thought traditional way to do
compile-time computation was like:

template<int N>
struct fib {
    static int const n = fib<N-1>::n + fib<N-2>::n;
};
template<>
struct fib<0> {
    static int const n = 0;
};
template<>
struct fib<1> {
    static int const n = 1;
};

(or using enums) which behaves much better for me. local gurus will probably explain best why..

best regards,
mojmir

You're right. Judging from the resulting object file it's much cleaner and it also works for large values of N. Still I wonder why the second function template version of the algorithm in my previous e-mail behaves the way it does. Perhaps it's doing computation on 2^N integers?

Regards,
Guido

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux