Namespaces
Variants

std::hive<T,Allocator>::get_iterator

ja.cppreference.net から
 
 
 
 
iterator get_iterator( const_pointer p ) noexcept;
(1) (C++26 以降)
const_iterator get_iterator( const_pointer p ) const noexcept;
(2) (C++26 以降)
1) は、iterator を返します。これは p と同じ要素を指します。
2) は、const_iterator を返します。これは p と同じ要素を指します。

p が *this 内の要素を指していない場合、動作は未定義です。

引数

p - 要素へのポインタ

戻り値

p と同じ要素を指すイテレータ。

計算量

アクティブブロック (*this 内) の数に比例する。

例

#include <cassert>
#include <hive>
#include <iostream>

struct Bee { int id{}; };

int main()
{
    std::hive<Bee> bees;

    // populate the hive
    for (int id{}; id != 14; ++id)
        bees.emplace(++id);

    // get the address of the last element
    Bee* bee = &*--bees.end();
    std::cout << "bee->id = " << bee->id << '\n';

    // remove all elements with even id
    std::erase_if(bees, [](const Bee& bee) { return (bee.id % 2) == 0; });

    auto iter = bees.get_iterator(bee);
    assert(iter == --bees.end());
    std::cout << "iter->id = " << iter->id << '\n';
}

出力:

bee->id = 13
iter->id = 13

関連項目

先頭を指すイテレータを返す
(パブリックメンバ関数)
終端を指すイテレータを返す
(パブリックメンバ関数)
先頭を指す逆イテレータを返す
(パブリックメンバ関数)
終端を指す逆イテレータを返す
(パブリックメンバ関数)