TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24440 21
Why everyone hates on C/C++ source generation?

It allows me to do magical reflection-related things in both C and C++

* it's faster than in-language metaprogramming (see zig's metaprog for example, slows down hugely the compiler) (and codegen is faster because the generator can be written in C itself and run natively with -O3 instead of being interpreted by the language's metaprogramming vm, plus it can be easily be executed manually only when needed instead of at each compilation like how it happens with in language metaprog.).

* it's easier to debug, you can print stuff during the codegen, but also insert text in the output file

* it's easier to read, write and maintain, usually procedural meta programming in other languages can get very "mechanical" looking, it almost seems like you are writing a piece of the compiler (for example

pub fn Vec(comptime T: type) type {
const fields = _std.builtin.Type.StructField{
.{ .name = "x", .type = T, .defaultvalue = null, .iscomptime = false, .alignment = 0 },
.{ .name = "y", .type = T, .defaultvalue = null, .iscomptime = false, .alignment = 0 },
.{ .name = "z", .type = T, .defaultvalue = null, .iscomptime = false, .alignment = 0 },
.{ .name = "w", .type = T, .defaultvalue = null, .iscomptime = false, .alignment = 0 },
};
return @Type(.{ .Struct = .{
.layout = .auto,
.fields = fields0..,
.decls = &.{},
.istuple = false,
}});
}

versus sourcegen script that simply says "struct {name} ..."

\* it's the only way to do stuff like SOA for now.. and c++26 reflection looks awful (and super flow)

However I made a post about it on both r/C
Programming and r/cpp and everyone hated on it

https://redd.it/1pgoc4y
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
More from @r_cpp
  1. Oct 11, 2026VKRT NES Remaster — an open-source C++20 NES emulator with an observation-driven remasteri…
  2. Oct 11, 2026Right way to test async code https://redd.it/1x2wqgz @r_cpp
  3. Oct 10, 2026Yantra: an LALR(1) parser generator for C++23 Yantra: an LALR(1) parser generator for C++2…
  4. Oct 10, 2026Opting in, and back out again https://dryperspective.github.io/posts/opting-in/ https://re…
  5. Oct 10, 2026I’m Building Bursztyn OS a Polish Operating System From Scratch I’m building Bursztyn OS,…
  6. Oct 9, 2026std::variant, operator== and pattern matching I was thinking, wouldn't adding equality com…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →