Common Library  0.9.5
tadah_fussy::gadget::LessStr 構造体

文字列 "より小さい" 比較用関数オブジェクト [詳解]

std::binary_function< std::string, std::string, bool >を継承しています。

公開メンバ関数

 LessStr (bool nCase=false)
 大文字・小文字を無視するかを指定して構築 [詳解]
 
bool operator() (const std::string &s1, const std::string &s2) const
 s1 の方が小さければ true を返す [詳解]
 

フィールド

bool ignoreCase
 大文字・小文字を無視するなら true にする
 

詳解

文字列 "より小さい" 比較用関数オブジェクト

アルゴリズムで利用することを想定している。 例えば、大文字・小文字を無視して文字列の比較をした上でソートしたい場合は次のようにすればよい。

std::vector< std::string > str;
:
std::sort( str.begin(), str.end(), tadah_fussy::string::Less( true ) );

構築子と解体子

◆ LessStr()

tadah_fussy::gadget::LessStr::LessStr ( bool  nCase = false)
inline

大文字・小文字を無視するかを指定して構築

引数
nCase大文字・小文字を無視するなら true にする

関数詳解

◆ operator()()

bool tadah_fussy::gadget::LessStr::operator() ( const std::string &  s1,
const std::string &  s2 
) const
inline

s1 の方が小さければ true を返す

二つの文字列を先頭から順に比較し、不一致を見つけたら、s1 の文字コードの方が s2 より小さければ true、 逆の場合は false を返す。もしどちらかが末尾まで達した場合、s1 の方が短ければ true、 それ以外の場合は false を返す。ignoreCase が true なら、大文字と小文字の違いは無視される。

引数
s1比較対象文字列 1
s2比較対象文字列 2
戻り値
s1 < s2 なら true を返す

この構造体詳解は次のファイルから抽出されました: