summaryrefslogtreecommitdiffstats
path: root/src/include/util/impl/stlmap.H
diff options
context:
space:
mode:
authorMatt Derksen <v2cibmd@us.ibm.com>2016-05-16 16:36:51 -0500
committerBill Hoffa <wghoffa@us.ibm.com>2016-06-02 09:23:44 -0500
commit5c59bb5b9c89a173c6771d4db84abb53f4615d93 (patch)
tree2f20a3174c612c227e1a3f781b8c351d97e9e5f3 /src/include/util/impl/stlmap.H
parent6f5df0cc3724b5dd046e2dedc33036853289c840 (diff)
downloadtalos-hostboot-5c59bb5b9c89a173c6771d4db84abb53f4615d93.tar.gz
talos-hostboot-5c59bb5b9c89a173c6771d4db84abb53f4615d93.zip
Implement std::map::emplace()
Change-Id: Id3f42ac3e5edf6c65c420e60ac69d649cbaa1ed0 RTC:153697 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/24631 Reviewed-by: Christian R. Geddes <crgeddes@us.ibm.com> Tested-by: Jenkins Server Tested-by: FSP CI Jenkins Reviewed-by: A. P. Williams III <iawillia@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/include/util/impl/stlmap.H')
-rw-r--r--src/include/util/impl/stlmap.H27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/include/util/impl/stlmap.H b/src/include/util/impl/stlmap.H
index 392762892..cdf5824e4 100644
--- a/src/include/util/impl/stlmap.H
+++ b/src/include/util/impl/stlmap.H
@@ -5,7 +5,9 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
-/* COPYRIGHT International Business Machines Corp. 2012,2014 */
+/* Contributors Listed Below - COPYRIGHT 2012,2016 */
+/* [+] International Business Machines Corp. */
+/* */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
@@ -38,6 +40,7 @@
#include <util/traits/remove_const.H>
#include <algorithm>
+
#ifndef __UTIL_SPLAYTREE_NS
#define __UTIL_SPLAYTREE_NS ::Util::__Util_SplayTree_Impl
#endif
@@ -329,6 +332,28 @@ namespace Util
return (result.first)->second;
}
+ template <class... Args>
+ std::pair <iterator,bool> emplace ( Args&&... args )
+ {
+ _Node *p = new _Node(std::forward<Args>(args)...);
+
+ _Tree::node * hint_node = nullptr;
+
+ bool rc = iv_tree.find_hint((_Tree::node*)p, hint_node);
+ if (!rc)
+ {
+ // node not found, so insert new one
+ iv_tree.insert((_Tree::node*)p);
+ return make_pair(iterator(_TreeItr(&iv_tree, (_Tree::node*)p)), true);
+ }
+ else
+ {
+ // node already exists, delete new one
+ delete p;
+ return make_pair(iterator(_TreeItr(&iv_tree, (_Tree::node*)hint_node)), false);
+ }
+ }
+
std::pair<iterator,bool> insert(const value_type& x)
{
_Tree::node* n = NULL;
OpenPOWER on IntegriCloud