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

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

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

function
<queue>

std::priority_queue::push

void push(const value_type& x);           // (1) C++98
constexpr void push(const value_type& x); // (1) C++26

void push(value_type&& x);           // (2) C++11
constexpr void push(value_type&& x); // (2) C++26

概要

新たな要素を追加し、優先順に並べ替えを行う。

効果

  • (1) :

    c.push_back(x);
    push_heap(c.begin(), c.end(), comp);
    

  • (2) :

    c.push_back(move(x));
    push_heap(c.begin(), c.end(), comp);
    

戻り値

なし

例

#include <iostream>
#include <queue>

int main()
{
  std::priority_queue<int> que;

  que.push(3);
  que.push(1);
  que.push(4);

  while (!que.empty()) {
    const int& x = que.top();
    std::cout << x << std::endl;
    que.pop();
  }
}

出力

4
3
1

右辺値参照バージョンの使用可能状況

  • Clang: 9.0.1 ✅
  • GCC: 4.7.0 ✅
  • Visual C++: ??

参照

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