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::priority_queue::empty - cpprefjp C++日本語リファレンス

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

最終更新日時: 2026年08月25日 12時11分17秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<queue>

std::priority_queue::empty

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

概要

priority_queueが空か否か、つまり要素数が 0 か否かを判定する。

内部のコンテナの empty() メンバ関数を呼ぶ。

効果

return c.empty();

戻り値

要素数が0の場合はtrue、それ以外の場合はfalseを返す。

例

#include <iostream>
#include <queue>

int main()
{
  // 空のキュー
  {
    std::priority_queue<int> empty_que;

    if (empty_que.empty()) {
      std::cout << "empty_que is empty" << std::endl;
    }
    else {
      std::cout << "empty_que is not empty" << std::endl;
    }
  }

  // 非空のキュー
  {
    std::priority_queue<int> non_empty_que;
    non_empty_que.push(3);

    if (non_empty_que.empty()) {
      std::cout << "non_empty_que is empty" << std::endl;
    }
    else {
      std::cout << "non_empty_que is not empty" << std::endl;
    }
  }
}

出力

empty_que is empty
non_empty_que is not empty

参照

  • 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 01402520 — 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.