[PATCH] D53385: [Support] json::Value construction from std::vector<T> and std::map<string, T>.
Sam McCall via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 18 01:50:35 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344732: [Support] json::Value construction from std::vector<T> and std::map<string,T>. (authored by sammccall, committed by ).
Repository:
rL LLVM
https://reviews.llvm.org/D53385
Files:
llvm/trunk/include/llvm/Support/JSON.h
llvm/trunk/unittests/Support/JSONTest.cpp
Index: llvm/trunk/include/llvm/Support/JSON.h
===================================================================
--- llvm/trunk/include/llvm/Support/JSON.h
+++ llvm/trunk/include/llvm/Support/JSON.h
@@ -294,9 +294,13 @@
Value(json::Array &&Elements) : Type(T_Array) {
create<json::Array>(std::move(Elements));
}
+ template <typename Elt>
+ Value(const std::vector<Elt> &C) : Value(json::Array(C)) {}
Value(json::Object &&Properties) : Type(T_Object) {
create<json::Object>(std::move(Properties));
}
+ template <typename Elt>
+ Value(const std::map<std::string, Elt> &C) : Value(json::Object(C)) {}
// Strings: types with value semantics. Must be valid UTF-8.
Value(std::string V) : Type(T_String) {
if (LLVM_UNLIKELY(!isUTF8(V))) {
Index: llvm/trunk/unittests/Support/JSONTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/JSONTest.cpp
+++ llvm/trunk/unittests/Support/JSONTest.cpp
@@ -47,6 +47,8 @@
s(Object{{"A", Object{{"B", Object{{"X", "Y"}}}}}}));
EXPECT_EQ("null", s(llvm::Optional<double>()));
EXPECT_EQ("2.5", s(llvm::Optional<double>(2.5)));
+ EXPECT_EQ("[[2.5,null]]", s(std::vector<std::vector<llvm::Optional<double>>>{
+ {2.5, llvm::None}}));
}
TEST(JSONTest, StringOwnership) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53385.170051.patch
Type: text/x-patch
Size: 1345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181018/1acaafb9/attachment.bin>
More information about the llvm-commits
mailing list