Engine → Core
slot_map.h
Dense storage addressed by generational keys. Insertion returns a key that stays valid until that element is erased; afterwards find() returns nullptr for it, even when the slot has been reused. Not thread-safe; concurrent const access is fine. T must be move-constructible and move-assignable (swap-remove). Pointers returned by find() and references and iterators obtained during iteration are invalidated by insert, emplace, erase, clear and reserve. A moved-from map is empty (no slots) and reusable.
Structs
Classes
| File |
Description |
slot_map |
Dense storage addressed by generational keys. Insertion returns a key that stays valid until that element is erased; afterwards find() returns nullptr for it, even when the slot has been reused. Not thread-safe; concurrent const access is fine. T must be move-constructible and move-assignable (swap-remove). Pointers returned by find() and references and iterators obtained during iteration are invalidated by insert, emplace, erase, clear and reserve. A moved-from map is empty (no slots) and reusable. |
slot_map_entry |
What a slot_map stores and what its iterators point at: the key and the element. Supports structured bindings (auto &[key, value] binds straight into the map's storage) and key()/value() accessors. The key is read-only; changing it would corrupt the map. |
Type Aliases
slot_map::const_iterator
using const_iterator = const entry *;
slot_map::entry
using entry = slot_map_entry<Key, T>;
slot_map::generation_type
using generation_type = std::remove_cvref_t<decltype(Key::generation)>;
slot_map::index_type
using index_type = std::remove_cvref_t<decltype(Key::index)>;
slot_map::iterator
using iterator = entry *;
slot_map::key_type
slot_map::size_type
slot_map::value_type
std::tuple_element<0, conjure::core::slot_map_entry<Key, T>>::type
std::tuple_element<1, conjure::core::slot_map_entry<Key, T>>::type
Concepts
slot_key_type
template <typename Key> concept slot_key_type = std::is_trivially_copyable_v<Key> && std::is_default_constructible_v<Key> && std::unsigned_integral<std::remove_cvref_t<decltype(Key::index)>> && std::unsigned_integral<std::remove_cvref_t<decltype(Key::generation)>> && sizeof(Key::index) <= sizeof(u32) && sizeof(Key::generation) <= sizeof(u32) && requires( Key key, std::remove_cvref_t<decltype(Key::index)> index, std::remove_cvref_t<decltype(Key::generation)> generation ) { key.index = index; key.generation = generation; };
Requirements on a custom key type: trivially copyable, default constructible (the null key), with assignable unsigned index and generation fields of at most 32 bits each. Narrower fields are allowed: a u16 generation retires a slot after 65535 reuses.