[llvm] [llvm][ADT] Structured bindings for move-only types in `StringMap` (PR #114676)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 2 17:58:48 PDT 2024


================
@@ -147,25 +147,33 @@ class StringMapEntry final : public StringMapEntryStorage<ValueTy> {
 };
 
 // Allow structured bindings on StringMapEntry.
+
+template <std::size_t Index, typename ValueTy>
+decltype(auto) get(StringMapEntry<ValueTy> &E) {
+  static_assert(Index == 0 || Index == 1);
+  if constexpr (Index == 0)
+    return E.getKey();
+  if constexpr (Index == 1)
+    return E.getValue();
+}
+
 template <std::size_t Index, typename ValueTy>
 decltype(auto) get(const StringMapEntry<ValueTy> &E) {
-  static_assert(Index < 2);
+  static_assert(Index == 0 || Index == 1);
   if constexpr (Index == 0)
-    return E.first();
-  else
-    return E.second;
+    return E.getKey();
+  if constexpr (Index == 1)
----------------
kuhar wrote:

also here

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


More information about the llvm-commits mailing list