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>;
私は大文字と小文字を区別しない文字列比較を扱うのに役立つこのchar_traits派生関数を使っています。文字リテラルからci_stringsを構築するときは完璧にうまく動作しますが、私はしばしば1つまたは2つのstd :: stringsを持つ状況に直面しており、大文字と小文字を区別しないで比較したいと思います。 std :: stringからci_stringに変換するためのカスタムコンストラクタや代入/変換演算子を書く方法はありますか?それとも、std :: stringsを反復して各文字のtolowerを呼び出す以外の方法はありませんか?カスタム文字列型のコンストラクタ/代入演算子オーバーロードの書き方は?
'c_str()'を使用しますか? – Arunmu