std::hive<T,Allocator>::get_iterator - cppreference.com
From cppreference.com
iterator get_iterator( const_pointer p ) noexcept; |
(1) | (since C++26) |
const_iterator get_iterator( const_pointer p ) const noexcept; |
(2) | (since C++26) |
1) returns an iterator pointing to the same element as p.
2) returns a const_iterator pointing to the same element as p.
If p does not point to an element in *this, the behavior is undefined.
Parameters
| p | - | a pointer to the element |
Return value
An iterator pointing to the same element as p.
Complexity
Linear in the number of active blocks in *this.
Example
#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'; }
Output:
bee->id = 13 iter->id = 13
See also
| returns an iterator to the beginning (public member function) [edit] | |
| returns an iterator to the end (public member function) [edit] | |
| returns a reverse iterator to the beginning (public member function) [edit] | |
| returns a reverse iterator to the end (public member function) [edit] |