[llvm] MapVector: add C++17-style try_emplace and insert_or_assign (PR #71969)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 12 14:12:09 PST 2023


================
@@ -114,31 +114,56 @@ class MapVector {
     return Pos == Map.end()? ValueT() : Vector[Pos->second].second;
   }
 
-  std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &KV) {
-    std::pair<KeyT, typename MapType::mapped_type> Pair = std::make_pair(KV.first, 0);
-    std::pair<typename MapType::iterator, bool> Result = Map.insert(Pair);
+  template <typename... Ts>
+  std::pair<iterator, bool> try_emplace(const KeyT &Key, Ts &&...Args) {
+    std::pair<typename MapType::iterator, bool> Result =
+        Map.insert(std::make_pair(Key, 0));
     auto &I = Result.first->second;
     if (Result.second) {
----------------
dwblaikie wrote:

Structure binding might be more legible & less verbose here (& similarly elsewhere)

https://github.com/llvm/llvm-project/pull/71969


More information about the llvm-commits mailing list