fibonacci.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // RUN: %clang_cc1 -fsyntax-only %s
  2. template<unsigned I>
  3. struct FibonacciEval;
  4. template<unsigned I>
  5. struct Fibonacci {
  6. enum { value = FibonacciEval<I-1>::value + FibonacciEval<I-2>::value };
  7. };
  8. template<unsigned I>
  9. struct FibonacciEval {
  10. enum { value = Fibonacci<I>::value };
  11. };
  12. template<> struct Fibonacci<0> {
  13. enum { value = 0 };
  14. };
  15. template<> struct Fibonacci<1> {
  16. enum { value = 1 };
  17. };
  18. int array5[Fibonacci<5>::value == 5? 1 : -1];
  19. int array10[Fibonacci<10>::value == 55? 1 : -1];
  20. template<unsigned I>
  21. struct FibonacciEval2;
  22. template<unsigned I>
  23. struct Fibonacci2 {
  24. static const unsigned value
  25. = FibonacciEval2<I-1>::value + FibonacciEval2<I-2>::value;
  26. };
  27. template<unsigned I>
  28. struct FibonacciEval2 {
  29. static const unsigned value = Fibonacci2<I>::value;
  30. };
  31. template<> struct Fibonacci2<0> {
  32. static const unsigned value = 0;
  33. };
  34. template<> struct Fibonacci2<1> {
  35. static const unsigned value = 1;
  36. };
  37. int array5_2[Fibonacci2<5>::value == 5? 1 : -1];
  38. int array10_2[Fibonacci2<10>::value == 55? 1 : -1];
  39. template<unsigned I>
  40. struct Fibonacci3 {
  41. static const unsigned value = Fibonacci3<I-1>::value + Fibonacci3<I-2>::value;
  42. };
  43. template<> struct Fibonacci3<0> {
  44. static const unsigned value = 0;
  45. };
  46. template<> struct Fibonacci3<1> {
  47. static const unsigned value = 1;
  48. };
  49. int array5_3[Fibonacci3<5>::value == 5? 1 : -1];
  50. int array10_3[Fibonacci3<10>::value == 55? 1 : -1];