How can I have multiple parameter packs in a variadic template?

后端 未结 4 1582
情书的邮戳
情书的邮戳 2020-11-27 12:55

Function one() accepts one parameter pack. Function two() accepts two. Each pack is constrained to be wrapped in types A and B. Why is it

4条回答
  •  旧时难觅i
    2020-11-27 13:26

    The compiler needs a way to know where is the barrier between the two variadic templates. A clean way of doing this is to define one pack of arguments for an object and the second pack for a static member function. This can be appied to more than two variadic templates by nesting multiple structs in eachother. (keeping the last level as a function)

    #include 
    
    template
    struct Obj
    {
        template
        static void Func()
        {
            std::cout << sizeof...(First) << std::endl;
            std::cout << sizeof...(Second) << std::endl;
        }
    };
    
    int main()
    {
        Obj::Func();
        return 0;
    }
    

提交回复
热议问题