(Partially) specializing a non-type template parameter of dependent type

前端 未结 4 1909
难免孤独
难免孤独 2020-12-01 04:06

Maybe I\'m tired, but I\'m stuck with this simple partial specialization, which doesn\'t work because non-type template argument specializes a template parameter with

4条回答
  •  自闭症患者
    2020-12-01 04:35

    Solution using Yakk's solution:

    #include 
    #include 
    
    template  
    struct X {
      static const bool isZero = false;
    };
    
    template 
    struct X < T, N, typename std::enable_if::type > {
      static const bool isZero = true;
    };
    
    int main(int argc, char* argv[]) {
        std::cout << X ::isZero << std::endl;
        std::cout << X ::isZero << std::endl;
        return 0;
    }
    

    Live Demo

提交回复
热议问题