view src/fac.cc @ 8:b5a45f1fd761

Simple faculty example
author Lewin Bormann <lbo@spheniscida.de>
date Wed, 25 Mar 2020 15:44:15 +0100
parents
children
line wrap: on
line source

#include <iostream>

template<unsigned N>
struct Fac {
    static const unsigned value = N * Fac<N-1>::value;
};

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

int main(void) {

    std::cout << "3! = " << Fac<3>::value << std::endl;
    std::cout << "10! = " << Fac<10>::value << std::endl;
    return 0;
}