Sort CMap Key by String Length
- by Yan Cheng CHEOK
Previously, I am using STL map to perform the mentioned task.
struct ltstr
{
bool operator()(std::string s1, std::string s2) const
{
const int l1 = s1.length();
const int l2 = s2.length();
if (l1 == l2) {
// In alphabetical order.
return s1.compare(s2) < 0;
}
// From longest length to shortest length.
return l1 > l2;
}
};
std::map<std::string, int, ltstr> m;
How can I perform the same task using CMap?
// How to make key sorted by string length?
CMap<CString, LPCTSTR, int, int> m;