From 02f8c315e61ed0980dd090b943473da5e1cb1528 Mon Sep 17 00:00:00 2001 From: german77 <5944268+german77@users.noreply.github.com> Date: Thu, 13 Nov 2025 10:24:50 -0600 Subject: [PATCH 1/2] container: Implement StrTreeMap::ForEachConstContext --- include/container/seadStrTreeMap.h | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) 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 From 16860af4a4177824378c57257c0aed49dfa3b281 Mon Sep 17 00:00:00 2001 From: german77 <5944268+german77@users.noreply.github.com> Date: Wed, 3 Dec 2025 12:41:37 -0600 Subject: [PATCH 2/2] Add non const getter --- include/container/seadTreeMap.h | 2 ++ 1 file changed, 2 insertions(+) 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: