GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::unordered_set::empty - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. unordered_set
  3. unordered_set
  4. empty

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<unordered_set>

std::unordered_set::empty(C++11)

bool empty() const noexcept;               // (1) C++11
[[nodiscard]] bool empty() const noexcept; // (1) C++20
constexpr bool empty() const noexcept;     // (1) C++26

概要

コンテナが空かどうかを判定する。

戻り値

コンテナが空であれば true、そうでなければ false を返す。

例外

投げない。

計算量

定数

例

#include <iostream>
#include <unordered_set>

int main()
{
  std::cout << std::boolalpha;

  std::unordered_set<int> us;

  // 空
  std::cout << us.empty() << std::endl;

  us.insert(1);

  // 空ではない
  std::cout << us.empty() << std::endl;

  us.clear();

  // 空
  std::cout << us.empty() << std::endl;
}

出力

true
false
true

バージョン

言語

  • C++11

処理系

  • Clang: 3.0 ✅, 3.1 ✅
  • GCC: 4.4.7 ✅, 4.5.3 ✅, 4.6.3 ✅, 4.7.0 ✅
  • Visual C++: ?

実装例

template <class Key, class Hash, class Pred, class Allocator>
inline bool unordered_set<Key, Hash, Pred, Allocator>::empty() const noexcept {
  return size() == 0; // begin() == end() でも OK
}

関連項目

名前 説明
size 要素数の取得
max_size 格納可能な最大の要素数の取得

参照

  • P0600R1 [[nodiscard]] in the Library
    • C++20で[[nodiscard]]が付加された
  • P2422R1 Remove nodiscard annotations from the standard library specification
    • C++26で[[nodiscard]]指定が削除された
  • P3372R3 constexpr containers and adaptors
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.