QHashが空か確認
解説
isEmpty(),empty()はQHashが空かどうかを判別します.isEmpty()とempty()の処理内容は同じです.
定義は以下の通りです.
bool QHash::isEmpty () const
bool QHash::empty () const
要素数が0の時にtrueを返し,そうでないときにfalseを返します.
empty()はSTLに対する上位互換のために存在します.
使用例
#include <QTextCodec>
#include <QTextStream>
#include <QHash>
int main(int argc, char *argv[]) {
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QTextStream out(stdout);
QHash<QString, int> hash;
hash.insert("a", 0);
hash.insert("b", 1);
hash.insertMulti ("b", 2); // hash = {<a, 0>, <b, 1>, <b, 2>}
out << hash.isEmpty() << "\n"; // false
hash.
remove("a"); // hash = {<b, 1>, <b, 2>} out << hash.isEmpty() << "\n"; // false
hash.
remove("b"); // hash = {} out << hash.isEmpty() << "\n"; // true
return 0;
}
出力
0
0
1
最終更新:2011年09月23日 19:58