最終更新日時:
が更新

履歴 編集

function
<hive>

std::hive::get_iterator(C++26)

iterator get_iterator(const_pointer p) noexcept;             // (1) C++26
const_iterator get_iterator(const_pointer p) const noexcept; // (2) C++26

概要

*thisの要素を指すポインタpから、その要素を指すイテレータを取得する。

hiveは要素のポインタ・参照が安定しているため、要素のポインタを保持しておき、後からそのポインタを指すイテレータを復元する用途で使用できる。

事前条件

p*thisの要素を指していること。

戻り値

pと同じ要素を指すiteratorまたはconst_iterator

計算量

*thisのアクティブブロック数に対して線形時間

#include <hive>
#include <print>

int main()
{
  std::hive<int> h = {1, 2, 3};

  // 要素のポインタを保持しておく
  const int* p = &*h.begin();

  // ポインタからイテレータを復元する
  std::hive<int>::iterator it = h.get_iterator(p);

  std::println("{}", *it);

  // 復元したイテレータで要素を削除する
  h.erase(it);
  std::println("size = {}", h.size());
}

出力

1
size = 2

バージョン

言語

  • C++26

処理系

関連項目

参照