I have the following function template:
template <typename K, typename V> void f(std::initializer_list<std::pair<const K, V>> il) {
I call the function as follows:
f({std::pair<const int,int>(1,2), std::pair<const int,int>(3,4)});
and it works great.
However, if I try to call it like this:
f({{1,2}, {3,4}});
it cannot infer the correct type, and I get a compilation error in the lines:
'no matching function for call to 'f(<brace-enclose initializer list>) note candidate is: note: template <class K, class V> void f(std::initializer_list<std::pair<const K, V>>)'
If I call it this way:
f({std::pair<const int,int>(1,2), {3,4}});
type inference works, but if I try and name it like this:
f({std::make_pair(1,2), {3,4}});
I get the same compilation error as before.
My question is:
Why does template type inference work in (c) but not in (d)?
(The compiler is gcc v4.6.3, with the flag -std = C ++ 11)
I looked at similar, older SO posts, but they didn't seem to answer this question.