[PATCH] D59142: YAMLIO: Improve template arg deduction for mapOptional
Pavel Labath via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 02:19:17 PDT 2019
labath updated this revision to Diff 190383.
labath added a comment.
Apply the same fix to mapOptionalWithContext to maintain a consistent interface.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59142/new/
https://reviews.llvm.org/D59142
Files:
include/llvm/Support/YAMLTraits.h
unittests/Support/YAMLIOTest.cpp
Index: unittests/Support/YAMLIOTest.cpp
===================================================================
--- unittests/Support/YAMLIOTest.cpp
+++ unittests/Support/YAMLIOTest.cpp
@@ -823,7 +823,7 @@
io.mapRequired("f1", c.f1);
io.mapRequired("f2", c.f2);
io.mapRequired("f3", c.f3);
- io.mapOptional("f4", c.f4, MyFlags(flagRound));
+ io.mapOptional("f4", c.f4, flagRound);
}
};
}
@@ -1327,8 +1327,8 @@
static void mapping(IO &io, TotalSeconds &secs) {
MappingNormalization<NormalizedSeconds, TotalSeconds> keys(io, secs);
- io.mapOptional("hours", keys->hours, (uint32_t)0);
- io.mapOptional("minutes", keys->minutes, (uint8_t)0);
+ io.mapOptional("hours", keys->hours, 0);
+ io.mapOptional("minutes", keys->minutes, 0);
io.mapRequired("seconds", keys->seconds);
}
};
Index: include/llvm/Support/YAMLTraits.h
===================================================================
--- include/llvm/Support/YAMLTraits.h
+++ include/llvm/Support/YAMLTraits.h
@@ -863,8 +863,8 @@
mapOptionalWithContext(Key, Val, Ctx);
}
- template <typename T>
- void mapOptional(const char *Key, T &Val, const T &Default) {
+ template <typename T, typename DefaultT>
+ void mapOptional(const char *Key, T &Val, const DefaultT &Default) {
EmptyContext Ctx;
mapOptionalWithContext(Key, Val, Default, Ctx);
}
@@ -890,10 +890,11 @@
this->processKey(Key, Val, false, Ctx);
}
- template <typename T, typename Context>
- void mapOptionalWithContext(const char *Key, T &Val, const T &Default,
+ template <typename T, typename Context, typename DefaultT>
+ void mapOptionalWithContext(const char *Key, T &Val, const DefaultT &Default,
Context &Ctx) {
- this->processKeyWithDefault(Key, Val, Default, false, Ctx);
+ const T &DefaultAsT = Default; // Use only implicit conversions.
+ this->processKeyWithDefault(Key, Val, DefaultAsT, false, Ctx);
}
private:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59142.190383.patch
Type: text/x-patch
Size: 2015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190313/e911c9a3/attachment.bin>
More information about the llvm-commits
mailing list