How to properly use references with variadic templates

前端 未结 3 1369
你的背包
你的背包 2021-02-04 08:06

I have something like the following code:

   template
   void inc(T1& t1, T2& t2, T3& t3, T         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 08:29

    I would not use rvalue references here, because that will allow you to bind to rvalues which can allow such nonsensical code as:

    inc(1);
    

    So, I would stick with regular references:

    template
    void inc(T& t) { ++t; }
    
    template
    void inc(T& t, Args& ... args) { ++t; inc(args...); }
    

提交回复
热议问题