variadic function template without formal parameters

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

This is what I\'m trying to do:

// base case
void f() {}

template 
void f() {
             


        
3条回答
  •  醉梦人生
    2021-01-05 02:00

    Since class templates can be partially specialized, another possibility is to use class templates to do the work, and have your function delegate to them:

    template
    struct caller
    {
        static void call() { } // Base case, terminates recursion
    };
    
    template
    struct caller
    {
        static void call()
        {
            // Do something with T
            caller::call();
        }
    };
    
    template
    void f() {
        caller::call();
    }
    

提交回复
热议问题