Reputation: 355
Could any one tell why this function object doesn't need the specified the type?
class StringPtrTmplLess
{
public:
template<typename PtrType>
bool operator()(const PtrType * lhs, const PtrType * rhs)
{
return *lhs < *rhs;
}
};
int main()
{
set<string*, StringPtrTmplLess> s2;
return 0;
}
how does the compiler know which specified type it will initialize the StringPtrTmplLess with?
Upvotes: 1
Views: 65
Reputation: 361512
It is because of template argument deduction which means the template argument is deduced from the type of the argument passed to the function call. This type deduction is done by the compiler. Go through the link which explains it in great detail.
Upvotes: 3