1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
#include <iostream>

template <unsigned int v>
struct Fac
{
    static constexpr unsigned int value = v*Fac<v-1>::value;
};

template <>
struct Fac<0>
{
    static constexpr unsigned int value = 1;
};


template <unsigned int v>
struct Fibo
{
    static constexpr unsigned int value = Fibo<v-1>::value + Fibo<v-2>::value;
};

template <>
struct Fibo<1>
{
    static constexpr unsigned int value = 1;
};

template <>
struct Fibo<0>
{
    static constexpr unsigned int value = 1;
};

template <unsigned int v>
struct Foo
{
    static constexpr unsigned int value = (v%2==0) ? Fac<v>::value
                                                   : Fibo<v>::value;
};

int
main()
{
    std::cout << Fibo<4>::value << std::endl;
    std::cout << Fibo<5>::value << std::endl;
    std::cout << Fac<4>::value << std::endl;
    std::cout << Fac<5>::value << std::endl;
    std::cout << Foo<4>::value << std::endl;
    std::cout << Fac<5>::value << std::endl;
}