Why can't the std :: initializer_list type be excluded in this case?

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

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

      

My compiler clang 5.0

.

The error message looks like this:

f ({1, 2, 3}); // error: there is no corresponding function to call in 'f'

note: template candidate is ignored: unable to infer template argument 'T'

Why is this f(coll)

ok but f({ 1, 2, 3 })

not?

+3


source to share





All Articles