[llvm] ebbe970 - [Support] Simplify mapOptionalWithContext (NFC) (#137529)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 14:09:01 PDT 2025


Author: Kazu Hirata
Date: 2025-04-27T14:08:58-07:00
New Revision: ebbe970c86c99eeee5e480346847dbe6bcb1c95e

URL: https://github.com/llvm/llvm-project/commit/ebbe970c86c99eeee5e480346847dbe6bcb1c95e
DIFF: https://github.com/llvm/llvm-project/commit/ebbe970c86c99eeee5e480346847dbe6bcb1c95e.diff

LOG: [Support] Simplify mapOptionalWithContext (NFC) (#137529)

We can use "constexpt if" to combine the two variants of functions.

---------

Co-authored-by: Nikita Popov <github at npopov.com>

Added: 
    

Modified: 
    llvm/include/llvm/Support/YAMLTraits.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index 21829b906967e..212b60a4ce6c4 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -901,11 +901,12 @@ class IO {
   }
 
   template <typename T, typename Context>
-  std::enable_if_t<has_SequenceTraits<T>::value, void>
-  mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
-    // omit key/value instead of outputting empty sequence
-    if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
-      return;
+  void mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
+    if constexpr (has_SequenceTraits<T>::value) {
+      // omit key/value instead of outputting empty sequence
+      if (this->canElideEmptySequence() && Val.begin() == Val.end())
+        return;
+    }
     this->processKey(Key, Val, false, Ctx);
   }
 
@@ -916,12 +917,6 @@ class IO {
                                 /*Required=*/false, Ctx);
   }
 
-  template <typename T, typename Context>
-  std::enable_if_t<!has_SequenceTraits<T>::value, void>
-  mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
-    this->processKey(Key, Val, false, Ctx);
-  }
-
   template <typename T, typename Context, typename DefaultT>
   void mapOptionalWithContext(const char *Key, T &Val, const DefaultT &Default,
                               Context &Ctx) {


        


More information about the llvm-commits mailing list