C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Proposing handle_map. As a response to std::hive.

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Mon, 13 Jul 2026 23:05:08 -0400
On Mon, Jul 13, 2026 at 10:12 PM A Johnston <ajohnston54637_at_[hidden]>
wrote:

>
> The details of that implementation are the opposite of what I was trying
> to advocate for. slot_map uses sparse paged allocation with stable pointers
> the same way std::hive does. My arguments about high frequency iteration
> over std::hive apply the same w.r.t. slot_map. I would like a dense
> non-paged array of values
>

That's what template parameter `Container` is for, and it defaults to
`std::vector`, which *is* a dense (in fact, contiguous) array of values.
The innards of sg14::slot_map
<https://github.com/Quuxplusone/SG14/blob/master/include/sg14/slot_map.h#L410-L414>
are just three std::vectors.
`this->reverse_map_` and `this->values_` both obey the invariant that their
`size()` is always equal to `this->size()` (i.e., they contain no
irrelevant elements).
Your `m_values_` is my `values_`; your `m_slots_` is my `slots_` +
`reverse_map_` AoS <https://en.wikipedia.org/wiki/AoS_and_SoA>'ed together.
Your `m_mask_` is the part I don't understand at the moment.


> and the ability for references held by other languages to be broken
> without RAII.
>

That's what the template parameter `Key` is for, right? (In sg14::slot_map,
`Key` defaults to `pair<unsigned, unsigned>`, where the first element of
the pair is the index and the second element is the generation counter.)
The fact that `insert` returns a `key_type` (your `hxhandle_t`), rather
than an `iterator`, is what makes the thing a slot-map instead of an
ordinary std::map or std::flat_map.


> I also proposed a 40-50 bit "generation" counter (even on 32-bits as
> compared to 10) before the handle id wraps. That is far larger than slot_map
> as I didn't want to be responsible for causing data corruption at scale.
>

sg14::slot_map supports arbitrary (user-defined) `key_type`. There are unit
tests
<https://github.com/Quuxplusone/SG14/blob/master/test/slot_map_test.cpp#L17-L36>
for that scenario (for values of "40–50" equal to 5).


> In my mind the question is as much about the kind of language C++ is
> trying to be. I have been "writing the world from scratch" in C++ for 20
> years. And maybe we like it that way. Other languages offer you a soup to
> nuts experience and all I would be doing right now is submitting a pull
> request on GitHub to get this merged.
>

(Merged to where? Whose GitHub?)

In this case I am talking about 400 LOC so far
>

Coincidentally, <sg14/slot_map.h> is also about 400 LOC. :) The unit tests
are longer than the facility itself.

–Arthur

>

Received on 2026-07-14 03:05:24