Template specialization for an empty parameter pack

后端 未结 3 787
走了就别回头了
走了就别回头了 2020-12-30 02:52

I have a variadic template function which calls itself to determine the largest number in a list (constituted by the templatized arguments). I am trying to make a specializa

3条回答
  •  星月不相逢
    2020-12-30 03:32

    I see two mistakes using clang.

    1. Put the overload taking a single int first.

    2. Make things unambiguous for lists of length 1. Recall that variadic lists can have zero size and when they do, it seems to me you have an ambiguity.

    This compiles and runs correctly for me:

    #include 
    
    using namespace std;
    
    template 
    int tmax() {
        return N;
    }
    
    template 
    int tmax() {
        return N > tmax() ? N : tmax();
    }
    
    int main() {
        cout << tmax<32, 43, 54, 12, 23, 34>();
    }
    

    54

提交回复
热议问题