Calculating and printing factorial at compile time in C++

前端 未结 4 819
逝去的感伤
逝去的感伤 2020-12-01 12:34
template
struct Factorial {
    enum { value = n * Factorial::value};
};

template<>
struct Factorial<0> {
    enum {val         


        
4条回答
  •  悲哀的现实
    2020-12-01 12:59

    I am sure it is far too late, but still.

    // definition
    template
    struct print_constexpr{
        [[deprecated]]
        print_constexpr(){ }
    };
    
    // usage
    print_constexpr::value> x;
    
    // output
    {path to file}: warning: ‘print_constexpr::print_constexpr() [with T = unsigned int; T N = 120]’ is deprecated [-Wdeprecated-declarations]
        print_constexpr::value> x;
    

提交回复
热议问题