Get the latest tech news

Code Generation in Rust vs. C++26


One of the things I like to do is compare how different languages solve the same problem — especially when they end up having very different approaches. It’s always educational. In this case, a bunch of us have been working hard on trying to get reflection — a really transformative language feature — into C++26. Fundamentally, reflection itself can be divided into two pieces:

P2996(Reflection for C++26) is the (huge) core proposal that fundamentally deals with the first problem, along with setting the foundation for being able to extend this feature in lots of different directions in the future, including generation (for which our design is P3294). And once we have that, the body of the specialization can introspect on T to get all the information that we need to display: we can iterate over all the non-static data members, formatting their name and value. This seems surprising that it’s necessary — since again conceptually the C++ approach is the same as the Rust one, and you might expect that adding the annotation injects the very specific, explicit specialization which cannot possibly be ambiguous with anything.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Rust

Rust

Photo of code generation

code generation

Photo of C++26

C++26

Related news:

News photo

Comparing our Rust-based indexing and querying pipeline to Langchain

News photo

Busd Taking Shape As A D-Bus Broker Written In Rust

News photo

Qodo raises $40M Series A to bring quality-first code generation and testing to the enterprise