- slot_map
-
NOTE: we using slightly patched 'reference implementation implemented by Arthur O'Dwyer for the SG14' (from here)
Patches contains the next changes, needed to adapt it for C++11:
-
Explicit types, instead of
auto
:using index_type = typename Key::first_type; using generation_type = typename Key::second_type; static constexpr index_type get_index(const Key& k) { return std::get<0>(k); } static constexpr generation_type get_generation(const Key& k) { return std::get<1>(k); }
-
constexpr
almost everywhere changed intoinline
, since in such places it allowed only since C++20, but in C++11std::vector
is notconstexpr
. -
Added
protected
accessor for internalslots_
:inline Container<key_type>& s() & noexcept { return slots_; } inline const Container<key_type>& s() const& noexcept { return slots_; } inline Container<key_type>&& s() && noexcept { return std::move(slots_); } inline const Container<key_type>&& s() const&& noexcept { return std::move(slots_); }
Specially to be able to iterate over
slot_map
not only byvalues
, but overkey
andvalue
simultaneously (needed for tests):template <typename T> class SlotMap : public stdext::slot_map<T, DefaultKey> { public: // ... template <typename F> void for_each(F&& callback) const { const auto& keys = base_t::s(); // accessor to `slot_map::slots_` const auto& values = base_t::c(); // accessor to `slot_map::values_` assert(values.size() <= keys.size()); const size_t values_size = values.size(); for(size_t i = 0; i < values_size; ++i) { const auto& key = keys[i]; const auto& value = values[i]; callback(key, value); } } };
It can be used in the next way:
taffy.nodes.for_each([&](const DefaultKey& key, const NodeData& value) { // ... };
-
Minor formatting
-
-