From 944bf0da1df11b26b40b5ae061caef21499f43fe Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 27 Apr 2025 09:04:55 -0700 Subject: [PATCH 1/2] [Support] Simplify mapOptionalWithContext (NFC) We can use "constexpt if" to combine the two variants of functions. --- llvm/include/llvm/Support/YAMLTraits.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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 - std::enable_if_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::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 - std::enable_if_t::value, void> - mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) { - this->processKey(Key, Val, false, Ctx); - } - template void mapOptionalWithContext(const char *Key, T &Val, const DefaultT &Default, Context &Ctx) { From b64f69c5361b27dd28e7ce05aef6023eb0406e98 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 27 Apr 2025 12:30:41 -0700 Subject: [PATCH 2/2] Update llvm/include/llvm/Support/YAMLTraits.h Co-authored-by: Nikita Popov --- llvm/include/llvm/Support/YAMLTraits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h index 1a6094a92c6fd..913d927b6ee63 100644 --- a/llvm/include/llvm/Support/YAMLTraits.h +++ b/llvm/include/llvm/Support/YAMLTraits.h @@ -904,7 +904,7 @@ class IO { void mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) { if constexpr (has_SequenceTraits::value) { // omit key/value instead of outputting empty sequence - if (this->canElideEmptySequence() && !(Val.begin() != Val.end())) + if (this->canElideEmptySequence() && Val.begin() == Val.end()) return; } this->processKey(Key, Val, false, Ctx);