Skip to content

Commit ebbe970

Browse files
[Support] Simplify mapOptionalWithContext (NFC) (llvm#137529)
We can use "constexpt if" to combine the two variants of functions. --------- Co-authored-by: Nikita Popov <[email protected]>
1 parent 4ca8f65 commit ebbe970

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,12 @@ class IO {
901901
}
902902

903903
template <typename T, typename Context>
904-
std::enable_if_t<has_SequenceTraits<T>::value, void>
905-
mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
906-
// omit key/value instead of outputting empty sequence
907-
if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
908-
return;
904+
void mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
905+
if constexpr (has_SequenceTraits<T>::value) {
906+
// omit key/value instead of outputting empty sequence
907+
if (this->canElideEmptySequence() && Val.begin() == Val.end())
908+
return;
909+
}
909910
this->processKey(Key, Val, false, Ctx);
910911
}
911912

@@ -916,12 +917,6 @@ class IO {
916917
/*Required=*/false, Ctx);
917918
}
918919

919-
template <typename T, typename Context>
920-
std::enable_if_t<!has_SequenceTraits<T>::value, void>
921-
mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
922-
this->processKey(Key, Val, false, Ctx);
923-
}
924-
925920
template <typename T, typename Context, typename DefaultT>
926921
void mapOptionalWithContext(const char *Key, T &Val, const DefaultT &Default,
927922
Context &Ctx) {

0 commit comments

Comments
 (0)