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
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌
関連項目
参照
- P0447R28 Introduction of
std::hiveto the standard library- C++26で
hiveが追加された
- C++26で