diff --git a/include/container/seadStrTreeMap.h b/include/container/seadStrTreeMap.h index 2402f6b2..d536d8b4 100644 --- a/include/container/seadStrTreeMap.h +++ b/include/container/seadStrTreeMap.h @@ -38,6 +38,22 @@ class StrTreeMap : public TreeMapImpl char mKeyData[MaxKeyLength + 1]; }; + template + class ForEachConstContext + { + public: + ForEachConstContext(const T& callback) : context(callback) {} + + void call(TreeMapNode* node) + { + Node* strNode = static_cast(node); + context(strNode->key(), strNode->value()); + } + + private: + const T& context; + }; + void allocBuffer(s32 node_max, Heap* heap, s32 alignment = sizeof(void*)); void setBuffer(s32 node_max, void* buffer); void freeBuffer(); @@ -153,12 +169,14 @@ inline typename StrTreeMap::Node* StrTreeMap::find(const Saf template template -inline void StrTreeMap::forEach(const Callable& delegate) const +inline void StrTreeMap::forEach(const Callable& callback) const { - MapImpl::forEach([&delegate](auto* base_node) { - auto* node = static_cast(base_node); - delegate(node->key(), node->value()); - }); + ForEachConstContext ctx(callback); + + Delegate1, typename MapImpl::Node*> delegate( + &ctx, &ForEachConstContext::call); + + MapImpl::forEach(delegate); } template diff --git a/include/container/seadTreeMap.h b/include/container/seadTreeMap.h index 08e0c9e2..a251cf7b 100644 --- a/include/container/seadTreeMap.h +++ b/include/container/seadTreeMap.h @@ -110,6 +110,8 @@ class TreeMapNode virtual ~TreeMapNode() = default; virtual void erase_() = 0; + Key& key() { return mKey; } + const Key& key() const { return mKey; } protected: