The following code prints "First". Why the 1st template is selected, while the the 2nd one seems to be more specialized and should be a better match? (I use MSVC10)
I understand that it's somehow related to the fact that the second template accepts its argument by const &
, but still can't realize why this make it a worse match.
#include <map>
#include <iostream>
template<class Range>
void go(Range &r)
{
std::cout << "First" << std::endl;
}
template<class K, class V>
void go(const std::map<K, V> &m)
{
std::cout << "Second" << std::endl;
}
int main()
{
std::map<int, int> m;
go(m);
}