SlotMap and Key in std
A general-purpose SlotMap<T> with typed Key<T>s in std, and no ECS; chosen by the
user on 2026-10-22.
T-0004 had proposed a game-framed Pool<T>/Handle<T>. The user asked whether that
belongs in a standard library at all, since no mainstream language ships one and games use
frameworks such as flecs or EnTT. The answer settled on:
- The container is general, the framework is not. A stable, typed ID that reads as
absent once its value is gone serves compilers, GUI trees, graphs and connection tables
as much as games. An ECS — archetypes, queries, systems — stays out of
stdfor good. - Dazzle has a reason the others do not: D-0003 keeps references out of fields, so a
struct that refers to something it does not own needs an ID. Rust’s
slotmapcrate is popular for the same reason. - Named
SlotMapandKey, notPoolandHandle: §14.2 already promises aPool<T>allocator, andHandleis what §14.5 callsRc,WeakandBox. - A lookup is a pointer,
get(k) -> ^T, asHashMap::getis (§9.1). A key does not implementNullableand cannot be resolved byoron its own, since it needs its map; no language change was wanted for it. - Dense storage: the values in one array, removal moving the last into the gap, so
iterating is a linear scan and
values()is a slice. Order is not kept, as aHashMap’s is not. - Versions by parity: odd while a slot holds a value, even while it is free, so a forged or null key (version 0) never names a free slot. After 2³¹ reuses of one slot the version comes round again; that is accepted rather than retiring the slot.
