Why can't the type of std::initializer_list be deducted in such a case?

Viewed 66
template<typename T>
void f(T)
{}

int main()
{
    auto coll = { 1, 2, 3 };
    f(coll); // ok
    f({ 1, 2, 3 }); // error
}

My compiler is clang 5.0.

The error message is as follows:

f({ 1, 2, 3 }); // error : no matching function for call to 'f'

note: candidate template ignored: couldn't infer template argument 'T'

Why is that f(coll) is ok but f({ 1, 2, 3 }) is not?

0 Answers
Related