How to write a variadic template recursive function?

后端 未结 6 1205
走了就别回头了
走了就别回头了 2020-12-09 03:39

I\'m trying to write a variadic template constexpr function which calculates sum of the template parameters given. Here\'s my code:

template<         


        
6条回答
  •  醉酒成梦
    2020-12-09 04:16

    Just sum it up the usual way.

    template
    constexpr int f() {
       int sum = 0;
       for(int i : { Args... }) sum += i;
       return sum;
    }
    

提交回复
热议问题