variadic function template without formal parameters

后端 未结 3 1993
無奈伤痛
無奈伤痛 2021-01-05 01:00

This is what I\'m trying to do:

// base case
void f() {}

template 
void f() {
             


        
3条回答
  •  旧巷少年郎
    2021-01-05 01:52

    Another way is turning the non-template function f into a variadic template function which accepts zero or more template arguments (the other f requires one or more template arguments). Then to avoid ambiguity, SFINAE away this template function when the number of arguments is not zero. Well, a code is better than 1000 words:

    #include 
    
    template 
    typename std::enable_if::type f() {
    }
    
    template 
    void f() {
        // do something with T
        f();
    }
    

提交回复
热议问题