Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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

We can use "constexpt if" to combine the two variants of functions.
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/137529.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/YAMLTraits.h (+6-11)
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index e707a445012b5..1a6094a92c6fd 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) {

@kazutakahirata kazutakahirata merged commit ebbe970 into llvm:main Apr 27, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_constexpr_if_llvm_YAML branch April 27, 2025 21:13
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
We can use "constexpt if" to combine the two variants of functions.

---------

Co-authored-by: Nikita Popov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants