I am trying to write a generic sort function in C++ using templates, but I am stuck in writing the greater function which returns true if lhs > rhs
template <typename T>
bool Sorter<T>::greater(T lhs, T rhs)
{
return lhs > rhs;
}
The above code will take care of simple types such as int, long. What should I do so that the code works for std::string, std::string&, const char *. A code sample will be a great help.
I’d say the only one you’d have to worry about is
const char*,std::stringshould already haveoperator>defined somewhere… (normally in<string>)For
const char*, provide a specialization.. e.g..