4

std::map大文字と小文字を区別せずに文字列を比較するためのコンパレータ機能オブジェクトを作成しました。

class CaseInsensitiveCmp
{
public:
    bool operator() (const std::string& op1, const std::string& op2) const
    {
        std::string op1low(op1.size(),'c'), op2low(op2.size(),'c');
        std::transform(op1.begin(), op1.end(),op1low.begin(),::tolower);
        std::transform(op2.begin(), op2.end(),op2low.begin(),::tolower);
        return op1low<op2low;
    }
};

問題は、メンバー関数 (operator() ) が const 関数でない場合、つまり

 bool operator() (const std::string& op1, const std::string& op2);

コンパイラ XLC コンパイラがエラーを生成する

CaseInsensitiveCmp::operator()(const std::string &, const std::string &)" is not a viable candidate.

比較機能オブジェクトメンバー関数は const でなければならないという C++ 標準の任意のポイントを参照できますか?

4

0 に答える 0