Variadic Templates - different types of expansion

前端 未结 2 1707
北海茫月
北海茫月 2020-12-30 07:59

Andrei Alexandrescu gave an excellent talk entitled: Variadic Templates are Funadic.

He presents the following 3 expansions which are subltey different:



        
2条回答
  •  长发绾君心
    2020-12-30 08:52

    Cases 2 and 3 really are very common in any kind of code involving variadic packs.

    template
    void f(T&&... t)
    {
        // Case 2:
        auto t2 = std::tuple(t...);
    
        // Case 3:
        auto t3 = std::make_tuple(std::forward(t)...);
    }
    

    Looking at my own code, I can't find any surviving example of case 1. I may have used it in the past in some detail namespace for a helper tempate, but I'm not sure. I don't think it's going to be common or even necessary most of the time.

提交回复
热议问题