2012-03-17 10 views
-1

私はそれを探しましたが、解決策を見つけることができませんでした。申し訳ありませんが、これは既に掲載されています。 constのchar *に私は::マップの構造マッピングのconst char型stxxlを作成する必要がSTXXLマップでconst char *を使用

*(最適には文字列に文字列になりますが、私はstxxlコンテナは非PODを受け入れない承知しています)

私が持っていますconst char *のcomp_type構造体を定義する際の問題です。誰かがその事例を持っていますか?

struct comp_type : public std::less<const char*> 
{ 
     static int max_value() 
     { 
       return (std::numeric_limits<char>::max)(); 
     } 
}; 
+0

'static int max_value()'を 'bool operator()(char const * const)const'に変更し、' int'ではなく 'bool'を返し、' std :: less < > '。標準ライブラリの比較関数が一般的にどのように機能しているかを調べていないため-1です。多くのサイトで詳細に説明されています。 – ildjarn

答えて

1

私はまだ、コメントするのに十分な評判を持っていない:

は、ここで私が書いた一つです。だから私は返信を投稿しています。

@ildjarn:stxxlの場合は、static T min_value()static T max_value()が必要な場合があります。

@Fabrizio:const char*を直接比較してもよろしいですか? std::less<const char*>から継承していることはあなたがしていることです。あなたの意図は、2つの文字列を比較するのであれば、あなたはそれがstatic const char* max_value()ないstatic int max_value()であることを、このような何か、

struct comp_type : public std::binary_function<const char*, const char*, bool> 
{ 
    bool operator()(const char* left, const char* right) 
    { 
     return strcmp(left, right) < 0; 
    } 

    static const char* min_value() { return "\0"; } // I hope this is the minimum 

    static const char* max_value() {...} // I don't know of any maximum value 
}; 

注意が必要です。お役に立てれば。

関連する問題