Use CString with CAtlMap and perform case insensitive lookup
While it is convenient to use CString as key element with CAtlMap, by default it will perform case-sensitive lookup which is not desired under certain conditions, e.g. use CAtlMap<CString> to hold query result from database, where we are hoping to perform case-insensitive lookup because column names are case-insensitive to most SQL languages.
To workaround the problem, the easiest way (I can find) is to use a modified string element trait like this:
/// Modified string element trait which does case insensitive comparison
return( nHash );
static bool __cdecl CompareElements( _In_ INARGTYPE str1, _In_ INARGTYPE str2 )
The code is simple and straightforward. To use it with CAtlMap (assuming use _variant_t as value):
|typedef CAtlMap<CString, _variant_t, CStringElementTraitsX> CAltMapX;|