1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// { dg-do run } // { dg-options "-std=c++0x" } //#include <iostream> #include <functional> #include <cassert> int main() { std::function<int(int)> fib = [&fib] (int n) -> int { //std::cerr << "fib(" << n << ")\n"; if (n <= 2) return 1; else return fib(n-1) + fib(n-2); }; assert(fib(5) == 5); assert(fib(10) == 55); return 0; }