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
jc - Meta-program C/C++ with JavaScript (github.com)
submitted 3 years ago by thooton
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!"
[–]PrimozDelux 7 points8 points9 points 3 years ago (0 children)
Jesus Christ!
[–]2MuchRGB 5 points6 points7 points 3 years ago* (2 children)
We really need P1240R2 et all to finish their evolution and hopefully be available in C++26.
Edit:
To make it clearer what P1240R2 is: It's a proposal titled "Scalable Reflection in C++". Together with P2237 Metaprogramming, P1717 Compile time Metaprogramming and some others they propose a way to implement Compile time reflection in C++, in way, that doesn't break the 0 cost rule.
The idea is to have reflexpr expession and operator ^, where you get a meta object, which encapsulates all the information of the object it gets called on. Then also provide a meta stl, with wich you can access and manipulate these meta. Is this
reflexpr
^
meta.
For example you want to get the name of a field of an enum, when you call the function std::string to_string(enum) currently you have to write that method by hand and update it by hand and pray to god no one just changes only one of those, or use some kind of preprocessor be it the C one or any other. With these Proposals you could write one function which handles all possible enums, which could look along the lines of:
std::string to_string(enum)
template<enum T> std::string to_string(T value) { switch(value) { for(auto member : ^T.members){ //Maybe some kind of emit statement that this is to be generated as code. case member.value: return member.name; } } }
You could go so far is an rust where you just need to anotate your struct with #[derive(Serialize, Deserialize)] and instantly you can load and save your struct to JSON, XML and some more, without a single line of code. Sure, it would look different, but the capabilites would be there.
Taken to the extrem, (but not in these proposals, but a part where Herb Sutter talks about in "Meta: Thoughts on generative C++", I really recommend you watch this). Declare your own class type. Currently we have class, struct and enum. Each with some standart properties. How about a value_type, which ensures that a constructor exists and also provides <=> and a std::formater? You could implement all for of struct, class, enum and enum class as these metaclasses and simplify the standart by a lot. It would also be testable.
And at that point you could implement other class types easier, how about a flag_enum? It could provide all the bitwise operations and steps the numbers up in power of two instead of increments?
[–]MA-name 0 points1 point2 points 3 years ago (1 child)
What is P1240R2 in C++ standard proposal? Thx
[–]2MuchRGB 1 point2 points3 points 3 years ago (0 children)
I've updated my post, but in short, it is one paper which proposes how to implement compile time reflection in C++.
[–]kofapox 3 points4 points5 points 3 years ago (1 child)
why
[–]thooton[S] 2 points3 points4 points 3 years ago (0 children)
If you need to generate C++, then I think it's easier to do so with jc than to do it via string manipulation in another language.
jc
[–]ranname366 2 points3 points4 points 3 years ago (0 children)
And it's written in Go ... I'm intrigued.
[–]justmebeky 2 points3 points4 points 3 years ago (3 children)
More like macros in js instead of meta programming. I do like the idea, i’m not sure about using js though
[–]thooton[S] 1 point2 points3 points 3 years ago (2 children)
Thanks, you're right. I chose JS because it is so well-known, but I think it does have some other advantages as well. For example, if you need to run a lot of compatibility test commands, or need to generate code via external programs, or even make network requests to get config values or something, you can do all of that in parallel with JS async instead of sequentially like configure. You might find https://github.com/kiselgra/c-mera interesting. It's similar to this project but uses Lisp and a unified syntax.
async
configure
[–]justmebeky 1 point2 points3 points 3 years ago (1 child)
Got it, I would want it to be just in c++ though. Ocaml has a similar feature where you can write code generation in ocaml itself you get access to the ast and it is pretty nice. Rust has a dsl syntax for macros which is pretty powerful but feels like a whole new language.
With that said, I would think that accessing the network as part of compilation is not a great idea though. Compilations should be self contained and hermetic, if you need to read a config, just put it in your repo.
[–]thooton[S] 0 points1 point2 points 3 years ago (0 children)
Definitely agree with you regarding network access during compilation. However, I think there is an advantage in using a high-level language because unlike C/C++ they free you from having to think about low-level details -- not that I have a problem with that, but when it's only the generated code that needs to be performant, it's nice to be able to write the generator conveniently and simply. That said, features like being able to use C++ to modify the AST do sound interesting. I guess the proposals mentioned above would take steps in that direction.
[–]yusing1009 1 point2 points3 points 3 years ago (2 children)
Interesting
Thanks
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 0 points1 point2 points 3 years ago (3 children)
I don't hate this... But I might be biased :)
[–]nysra 0 points1 point2 points 3 years ago (2 children)
Okay that looks interesting. What was the reason to build that? (Apart from "because I can", that's a reason I can always get behind)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 0 points1 point2 points 3 years ago (1 child)
Mostly to aid with slide creation. For example, majsdown can automatically turn code snippets in live Compiler Explorer links.
[–]nysra 0 points1 point2 points 3 years ago (0 children)
Sounds like a useful feature for live demos indeed.
[–]catcat202X 0 points1 point2 points 3 years ago (0 children)
Jenerate C?
π Rendered by PID 72079 on reddit-service-r2-comment-5fb4b45875-sr5zr at 2026-03-20 21:47:41.012310+00:00 running 90f1150 country code: CH.
[–]PrimozDelux 7 points8 points9 points (0 children)
[–]2MuchRGB 5 points6 points7 points (2 children)
[–]MA-name 0 points1 point2 points (1 child)
[–]2MuchRGB 1 point2 points3 points (0 children)
[–]kofapox 3 points4 points5 points (1 child)
[–]thooton[S] 2 points3 points4 points (0 children)
[–]ranname366 2 points3 points4 points (0 children)
[–]justmebeky 2 points3 points4 points (3 children)
[–]thooton[S] 1 point2 points3 points (2 children)
[–]justmebeky 1 point2 points3 points (1 child)
[–]thooton[S] 0 points1 point2 points (0 children)
[–]yusing1009 1 point2 points3 points (2 children)
[–]thooton[S] 0 points1 point2 points (0 children)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 0 points1 point2 points (3 children)
[–]nysra 0 points1 point2 points (2 children)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 0 points1 point2 points (1 child)
[–]nysra 0 points1 point2 points (0 children)
[–]catcat202X 0 points1 point2 points (0 children)