This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4600. Remove precondition on hive::get_iterator(), introduce Returns value when pointer is not within *this

Section: 23.3.9.5 [hive.operations] Status: New Submitter: Matt Bentley Opened: 2026-06-21 Last modified: 2026-06-21

Priority: Not Prioritized

View other active issues in [hive.operations].

View all other issues in [hive.operations].

View all issues with New status.

Discussion:

LEWG decided on the precondition for hive::get_iterator ("p points to an element in *this") on the basis that:

  1. (a) hive may free blocks during erasure, when they become empty of elements, which means accessing pointers to erased elements within that block is UB (see: P1726R5). The UB occurs before the get_iterator call (upon accessing the pointer's value to supply to the function), but it was felt that the precondition served as a warning to the user to the best of my recollection.

  2. (b) given that the above is the case, the same conditions should apply to T* pointers to elements within other container instances, hive or otherwise

I feel that this is a mistake because:

  1. It potentially leads to diverging implementation behaviours (and people may come to rely on that implementation behaviour, even though they shouldn't)

  2. It's inconsistent with how we deal with this situation in other containers. In most implementations of vector the iterator is a pointer and expanding the vector memory block invalidates it. But erase() doesn't require that the iterator point to an element within *this in the preconditions, and returns end() if it doesn't, as per 23.2.4 [sequence.reqmts] p45. Unlike get::iterator, the access of the pointer occurs within erase(), but there's no prevention of UB. Same stuff applies for erase() in the other containers.

  3. The pointer-zap rule may get changed at some point to make accessing a pointer to a non-allocated address defined behaviour, in which case that concern may not exist.

  4. It is easy in all the implementation styles I've seen to date or can imagine, for an implementation to detect whether or not a given pointer points to a value within *this.

  5. The precondition obviates better and more productive Returns behaviour, namely: returning end() when p doesn't point to an element in *this. This is more useful to developers in the context of bug-fixing a scenario where a pointer to an element in another container instance is accidentally supplied to this->get_iterator. The developer can see clearly what is at fault, rather than getting a random crash, termination or other behaviour. If the pointer-zap rule is relaxed, the latter could also be used in multithreaded access to hive in terms of determining whether or not a given element is 'live'.

  6. It is inappropriate for a precondition to primarily be something which is protecting against behaviour occuring outside of that function i.e. during the pointer access. This makes the standard less durable via blurred inter-thing responsibility.

Points against removing the precondition that I can think of:

  1. Pointer-zap rule may never be relaxed, but this has no impact on the inconsistency with the standard nor the use-case when the T* points into a different container.

  2. Forcing implementations to check whether or not the element pointed to by p is erased, could potentially obviate better performance in some hypothetical scenario (I can't imagine a scenario, but even my imagination is not without limits :). I say this because minor alterations to erase, range-erase and splice are required in the reference implementation, for this to take place. Those changes do not result in a performance difference.

If there is no change, at the very least this gives an opportunity for a record of why we decided not to do so.

Proposed resolution:

This wording is relative to N5046.

  1. Modify 23.3.9.5 [hive.operations] as indicated:

    iterator get_iterator(const_pointer p) noexcept;
    const_iterator get_iterator(const_pointer p) const noexcept;
    

    -17- Preconditions: p points to an element in *this.

    -18- Returns: An iterator or const_iterator pointing to the same element as p. If no such element exists, end() is returned.

    -19- Complexity: Linear in the number of active blocks in *this.