Having trouble passing multiple initializer lists to variadic function template

后端 未结 4 2150
自闭症患者
自闭症患者 2020-12-20 14:16

I don\'t understand the error message when trying to pass a variable number of initializer lists:

template
void foo(Values...)
{
}
         


        
4条回答
  •  温柔的废话
    2020-12-20 15:05

    The problem is likely deducibility. {} could be uniform initializers to any of the arguments.

    This works:

    #include 
    
    template
    void foo(std::initializer_list... args)
    {
    }
    
    template
    void foo(Values&&... args)
    {
    }
    
    int main()
    {    
        foo(1, 2, 3, "hello", 'a');
        foo({1}, {2, 3});
    }
    

    See it Live on Coliru

提交回复
热议问题