summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-recursive.C
blob: 1a12eab312ffa7eaf50fd8a750d2b42b280ac95d (plain)
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;
}