Namespaces
Variants

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

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

참조 항목

처음의 반복자를 반환합니다.
(공개 멤버 함수)
끝의 반복자를 반환합니다.
(공개 멤버 함수)
처음의 역방향 반복자를 반환합니다.
(공개 멤버 함수)
끝의 역방향 반복자를 반환합니다.
(공개 멤버 함수)