struct ci_char_traits : public std::char_traits<char>
{
static bool eq( char c1, char c2 ) { return toupper( c1 ) == toupper( c2 ); }
static bool ne( char c1, char c2 ) { return toupper( c1 ) != toupper( c2 ); }
static bool lt( char c1, char c2 ) { return toupper( c1 ) < toupper( c2 ); }
static int compare( const char* s1, const char* s2, size_t n );
static const char* find( const char* s, int n, char a );
};
using ci_string = std::basic_string<char, ci_char_traits>;
I'm working with this char_traits derivative which should help me dealing with case-insensitive string comparisons. It works perfectly fine when constructing ci_strings from character literals, however I'm often faced with the situation where I have one or two std::strings and would like to compare them case-insensitively. Is there some way to write a custom constructor or assignment/conversion operator to convert from std::string to ci_string or is there no other possibility than to iterate the std::strings and call tolower on each character?