c++ power of integer, template meta programming

后端 未结 4 1091
抹茶落季
抹茶落季 2020-12-08 17:01

I want to make a function which returns a power of integer. Please read the fmuecke\'s solution in power of an integer in c++ .

However, I want to generalize his so

4条回答
  •  被撕碎了的回忆
    2020-12-08 17:22

    Here is a simple solution:

    #include
    using namespace std;
    
    template
    struct Pow
    {
        enum { res = N * Pow::res};
    };
    
    
    template
    struct Pow
    {
        enum {res = 1};
    };
    int main()
    {
        cout<::res<<"\n";
    }
    

提交回复
热议问题