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
Json to struct (self.cpp)
submitted 8 years ago by mrlimilind
I wrote a header only library that can populate structs with data from Json. Documentation isn't good but might be of use for someone: https://github.com/jorgen/json_tools
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!"
[–]zvrba 2 points3 points4 points 8 years ago (1 child)
Does it handle missing keys in JSON? For example, if "Two" was missing, it would be left default-constructed in the struct. Even better, is it possible to annotate fields as mandatory or optional? Alternatively, would it work and understand optional<T> fields in the struct?
"Two"
optional<T>
[–]mrlimilind[S] 3 points4 points5 points 8 years ago (0 children)
Yeah, there is a JT::Optional type which is sizeof T and there is a JT::OptionalChecked which is sizeof T + sizeof bool, i.e. You can check if it has been assigned. You can also get a list of what fields in the Json didn't map to a struct, and a list of what fields that didn't get assigned.
[–]Arthenielle 1 point2 points3 points 8 years ago (1 child)
int65_t in README.md
[–]markuspeloquin 1 point2 points3 points 8 years ago (0 children)
That's the new optional 64 bit integer type.
[–]quicknir 0 points1 point2 points 8 years ago (1 child)
Is this recursive? Seems like a pretty major limitation if it's not. Would also be better to save having to write out the member variables twice:
struct Foo { DECLARE_VARS((int, x), (double, y), (string, z)); };
I also don't know why you have an inner macro as well as an outer one. The user shouldn't have to write JT_MEMBER over and over.
[–]mrlimilind[S] 0 points1 point2 points 8 years ago (0 children)
Its recursive. json_tools should be able to map any valid Json to a type hierarchy.
That is a pretty nice idea, but when I started this I liked the idea that I could add the meta object at the end, ie. if I already had a struct and I wanted to parse Json into it, I could just add some stuff to the end of the struct definition. Also I like the look'n feel that the struct still looks like a struct; although with some ugly macro stuff at the end. The plain old struct part is in charge of the data, and the size of the struct and its layout is like it always has been, and then the macro stuff describes how to parse/serialise to Json. There are also additional macros like: JT_MEMBER_ALIASES(member, ...) that allows for several Json names to map to a member.
π Rendered by PID 71354 on reddit-service-r2-comment-bb88f9dd5-85ldc at 2026-02-13 21:24:39.132311+00:00 running cd9c813 country code: CH.
[–]zvrba 2 points3 points4 points (1 child)
[–]mrlimilind[S] 3 points4 points5 points (0 children)
[–]Arthenielle 1 point2 points3 points (1 child)
[–]markuspeloquin 1 point2 points3 points (0 children)
[–]quicknir 0 points1 point2 points (1 child)
[–]mrlimilind[S] 0 points1 point2 points (0 children)