QHash > isEmpty

QHashが空か確認

解説

isEmpty(),empty()はQHashが空かどうかを判別します.isEmpty()とempty()の処理内容は同じです.

定義は以下の通りです.
bool QHash::isEmpty () const
bool QHash::empty () const
要素数が0の時にtrueを返し,そうでないときにfalseを返します.

empty()はSTLに対する上位互換のために存在します.

使用例

  1. #include <QTextCodec>
  2. #include <QTextStream>
  3. #include <QHash>
  4. int main(int argc, char *argv[]) {
  5. QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
  6. QTextStream out(stdout);
  7.  
  8. QHash<QString, int> hash;
  9. hash.insert("a", 0);
  10. hash.insert("b", 1);
  11. hash.insertMulti ("b", 2); // hash = {<a, 0>, <b, 1>, <b, 2>}
  12. out << hash.isEmpty() << "\n"; // false
  13. hash.remove("a"); // hash = {<b, 1>, <b, 2>}
  14. out << hash.isEmpty() << "\n"; // false
  15. hash.remove("b"); // hash = {}
  16. out << hash.isEmpty() << "\n"; // true
  17.  
  18. return 0;
  19. }

出力
0
0
1
最終更新:2011年09月23日 19:58
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。