[Support] Simplify mapOptionalWithContext (NFC) (#137529)
We can use "constexpt if" to combine the two variants of functions.
---------
Co-authored-by: Nikita Popov <github@npopov.com>
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index 21829b9..212b60a 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -901,11 +901,12 @@
}
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 @@
/*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) {