bytedance / sonic-cpp

A fast JSON serializing & deserializing library, accelerated by SIMD.
Apache License 2.0
835 stars 101 forks source link

Proposal: friendly list initialization for document or node. #58

Open liuq19 opened 1 year ago

liuq19 commented 1 year ago

Now, initialization is complex as follows:

Document doc;
doc.SetObject();
doc.AddMember(key, value);

Can we use the c++11 initialization list:

Document doc { {"a", "b"}, {"c", false}, {"d", {1, 2, 3}}};
xiegx94 commented 1 year ago

I don't think this is correct c++ syntax.

liuq19 commented 1 year ago

A typo has been fixed and C++11 has supported list initialization. However, the main issue is how to differentiate between object and array types. For a example, doc{"a", 1} may be Array["a", 1] and Object{"a", 1}.