Sort CMap Key by String Length
Posted
by Yan Cheng CHEOK
on Stack Overflow
See other posts from Stack Overflow
or by Yan Cheng CHEOK
Published on 2010-03-18T03:34:23Z
Indexed on
2010/03/18
3:41 UTC
Read the original article
Hit count: 293
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;
© Stack Overflow or respective owner