Re: Fibonacci-Folge / Benchmarks
Verfasst: Do Okt 12, 2017 6:48 am
ansonsten hätte ich noch das hier anzubieten:
... aber das lässt Du bestimmt nicht gelten...
Code: Alles auswählen
mfro@thinkpad:~/Dokumente/Development/scratch$ time ./tst101
30: 832040
real 0m0,004s
user 0m0,000s
sys 0m0,000s
Code: Alles auswählen
#include <iostream>
template <int N> struct Fib_t {
enum { value = Fib_t<N-1>::value + Fib_t<N-2>::value };
Fib_t() { std::cout << N << ": " << value << std::endl; }
};
// Explicitly specialized for N==2
template <> struct Fib_t<2> {
enum { value = 1 };
Fib_t() { std::cout << 2 << ": " << value << std::endl; }
};
// Explicitly specialized for N==1
template <> struct Fib_t<1> {
enum { value = 1 };
Fib_t() { std::cout << 1 << ": " << value << std::endl; }
};
int main(void)
{
Fib_t<30> f;
}