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

  1. リファレンス
  2. algorithm
  3. push_heap

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

履歴 編集

function template
<algorithm>

std::ranges::push_heap(C++20)

namespace std::ranges {
  template <random_access_iterator I,
            sentinel_for<I> S,
            class Comp = ranges::less,
            class Proj = identity>
    requires sortable<I, Comp, Proj>
  constexpr I
    push_heap(I first,
              S last,
              Comp comp = {},
              Proj proj = {}); // (1) C++20

  template <random_access_range R,
            class Comp = ranges::less,
            class Proj = identity>
    requires sortable<iterator_t<R>, Comp, Proj>
  constexpr borrowed_iterator_t<R>
    push_heap(R&& r,
              Comp comp = {},
              Proj proj = {}); // (2) C++20
}

概要

ヒープ化された範囲に要素を追加する

  • (1): イテレータ範囲を指定する
  • (2): Rangeを直接指定する

事前条件

  • [first,last - 1) は有効な heap である必要がある。

効果

last - 1 の値を、[first,last) が有効な heap となるように配置する

戻り値

last

計算量

最大で log(last - first) 回比較する。

例

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
  std::vector<int> v = {3, 1, 4};

  std::ranges::make_heap(v);

  // 要素を追加してヒープ化
  v.push_back(2);
  std::ranges::push_heap(v);

  std::ranges::sort_heap(v);

  for (int x : v) {
    std::cout << x << std::endl;
  }
}

出力

1
2
3
4

バージョン

言語

  • C++20

処理系

  • Clang: 16.0.6 ✅
  • GCC: 10.1.0 ✅
  • Visual C++: 2019 Update 10 ✅

参照

  • N4861 25 Algorithms library
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.