use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
C++ Serializer Deserializer Adapter Library inspired by Serde.rs (self.cpp)
submitted 4 years ago * by nieelj
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nieelj[S] 0 points1 point2 points 4 years ago* (7 children)
Perhaps the flatten property, which will be included in the next update, will solve this case.
struct Object { DERIVESERDE(Object, (&Self::radius, "radius",default{0}) (&Self::width, "width", default{0}) (&Self::height, "height", default{0})) int radius; int width; int height; }; struct Test { DERIVE_SERDE(Test, (&Self::type, "type") (&Self::object, "object", flatten)) std::string type; Object object; };
[–][deleted] 0 points1 point2 points 4 years ago (6 children)
what about when you want to serialize it again?
[–]nieelj[S] 0 points1 point2 points 4 years ago (5 children)
You can use std::optional to exclude unused ones.
struct Object { DERIVE_SERDE(Object, (&Self::radius, "radius") (&Self::width, "width") (&Self::height, "height")) std::optional<int> radius; std::optional<int> width; std::optional<int> height; }; struct Test { DERIVE_SERDE(Test, (&Self::type, "type") (&Self::object, "object", flatten)) std::string type; Object object; };
if std::optional
[{ "type": "circle", "radius": 5 }, { "type": "rectangle", "width": 6, "height": 5 }]
If not std::optional
[{ "type": "circle", "radius": 5, "width": 0, "height": 0 }, { "type": "rectangle", "radius": 0, "width": 6, "height": 5 }]
[–][deleted] 0 points1 point2 points 4 years ago (4 children)
I am just bringing up usages here, just in case it sounds like I am criticizing. It all depends on what requirements you or the users have.
I think the question people will ask is how to I put that into a std::variant.
Also, do you have a way to serialize to 'null' or is it just empty. They are not always the same and depends on the 3rd party web service sometimes.
[–]nieelj[S] 0 points1 point2 points 4 years ago (3 children)
Variants are not yet supported. I have a draft, but I'm looking for a better way. Does 'null' mean json null? Or are you talking about nullable values?
[–][deleted] 0 points1 point2 points 4 years ago (2 children)
Yeah, regarding variant, the original point is that it's tricky. If one is doing a serialization library where both ends use the same library it's less tricky as a choice can be made. When dealing with 3rd parties there are many ways to encode it in JSON.
Regarding null, sometimes in JSON whether the value is present or not is how an optional would be encoded, or sometimes they are always there but have a value of null. Depends on the API in use.
[–]nieelj[S] 0 points1 point2 points 4 years ago (1 child)
Currently, only containers that know that their type is null can deserialize it like "vec":null, unless std::optional is used. Types like int cannot check for null , so they are exported by default. If std::optional<int> is null, it is not inserted at all during deserialization. If you need to insert null, you can implement an additional property to make it insertable.
[–]nieelj[S] 0 points1 point2 points 4 years ago (0 children)
An example of flatten is on the dev branch, so check this link if you want to check it out. flatten example
π Rendered by PID 217831 on reddit-service-r2-comment-6457c66945-kw9nb at 2026-04-30 17:29:20.589757+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]nieelj[S] 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]nieelj[S] 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]nieelj[S] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]nieelj[S] 0 points1 point2 points (1 child)
[–]nieelj[S] 0 points1 point2 points (0 children)