#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; } |