stable_sort
is itself a template, the type of its third parameter is a template parameter. This means that you cannot pass a function template as the argument, because template argument deduction cannot apply here - there's nothing to tell which instantiation you'd be after. So you'd have to specify the template argument explicitly:
stable_sort(data.begin(), data.end(), comp2<int, int>);
However, you'll be better off if you provide a functor for that:
struct comp2
{
template <typename TElemA, typename TElemB>
bool operator() (pair<TElemA, TElemB> const & a, pair<TElemA, TElemB> const & b) const {
return a.first < b.first;
}
};
stable_sort(data.begin(), data.end(), comp2());
That way, the actual template argument deduction is postponed until the time when the desired types are known.