From 88a55be5619a91dcc1fbbd2608c4e8cede52ff5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Wed, 16 Apr 2025 23:01:33 -0300 Subject: [PATCH] add TryEmplace to TMap --- src/common/utility/tarray.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/common/utility/tarray.h b/src/common/utility/tarray.h index 25d6e0e7f..ac9d8beb1 100644 --- a/src/common/utility/tarray.h +++ b/src/common/utility/tarray.h @@ -1380,6 +1380,18 @@ public: return n->Pair.Value; } + template + VT &TryEmplace(const KT key, Args&&... args) + { + Node *n = FindKey(key); + if (n == NULL) + { + n = NewKey(key); + ::new(&n->Pair.Value) VT(std::forward(args)...); + } + return n->Pair.Value; + } + //======================================================================= // // Remove