C++ Variadic Function Templates of Known Type

前端 未结 4 1819
死守一世寂寞
死守一世寂寞 2021-01-04 09:43

I\'m currently trying to get my head around some of the things I can do with variadic template support. Let\'s say I have a function like this -

template <         


        
4条回答
  •  爱一瞬间的悲伤
    2021-01-04 10:01

    A variation of the top answer which will reject implicit conversion to int , if that is your preference:

    #include 
    
    void foo(int);
    
    template
    void foo(Arg1 first, Args... more)
    {
       static_assert(std::is_same_v, "foo called with non-int argument");
       foo(first);
       foo(more...);
    }
    

提交回复
热议问题