frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Discover C++26's compile-time reflection

https://lemire.me/blog/2025/06/22/c26-will-include-compile-time-reflection-why-should-you-care/
46•jandeboevrie•4h ago

Comments

npalli•3h ago
Also, it is worthwhile reading the standard proposal paper for lot of examples of how this might be used in the future.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p29...

PessimalDecimal•3h ago
Thanks for this link. Between it and the main article, I have a much better sense for how compile time reflection will actually be useful. The syntax is bad enough to make my eyes bleed, but at least they'll bleed for a good reason I hope.
techjamie•2h ago
> The syntax is bad enough to make my eyes bleed

That's on brand for C++ in general. It works well, but it's ugly as sin while doing it.

bestouff•1h ago
I don't agree with you. Yes syntax is often awful but no it doesn't work that well. It's a minefield of Undefined Behavior.
grg0•25m ago
I am happy^^ that ^^ is our quote character. ^^
layer8•2h ago
The rationale in section 2.2 for the single std::meta::info type is interesting. While having a single “dynamic” type is fine insofar as any type error would occur at compile time anyway, I wonder if there wouldn’t be a way to maintain future backwards compatibility for finer-grained meta types, as long as the language elements they reflect remain backwards-compatible in the language as well. From first principles, one would think that it should be possible for the backwards compatibility of the reflection system to mirror the backwards compatibility of the reflected language. I’d be interested in the underlying reasons for why this isn’t the case, if any.
jandrewrogers•3h ago
I am looking forward to compile-time reflection, C++ has unusually strong metaprogramming capabilities among systems languages and this will significantly bolster that.

C++ does not win any prizes for being the most aesthetically pleasing programming language but the new syntax around reflection is pretty ugly even by those standards.

paulddraper•1h ago
Correct on all counts
mystified5016•3h ago
Wow. That is... certainly some syntax. It reminds me of Perl.

This syntax is pretty weird even by C++ standards, and it's certainly the worst way to do reflection I've personally seen. But I guess it's good that C++ is finally getting some kind of reflection. Only a few decades late to the party but hey they got there in the end.

Really as C++ grows and evolves, I feel more and more that I'd rather use plain C than wrangle with all of the bizzarro choices C++ has made. C++ is more and more often just the wrong choice of language for anything I want to do. If I need compile-time reflection, I'll use a C# program to generate C code.

PessimalDecimal•3h ago
> compile-time reflection

> use a C# program to generate C code

These seem at odds.

jcelerier•2h ago
you call the C# program that generates the code as part of your build system
nine_k•3h ago
The comparison with Perl is apt, to my mind. Both Perl and C++ were early to their space, experimenting with concepts that were weird at the time, trying many approaches we now find ugly, and serving as examples of both successes and failures for the much better languages that came after them. The difference is that Perl5 stopped evolving some time ago, while C++ continues the same tendency unabashed.

(Scala is another example of such a language.)

stathibus•3h ago
Are you suggesting that reflection is a new fancy thing and c++ is paving the way?
nine_k•1h ago
No; OOP, metaprogramming, exceptions, etc were sort of new in early 1990s in an efficiently compiled language, so C++ was paving its part of way, in an awkward manner, trying hard to make abstractions zero-cost. (I mean mainstream; Common Lisp had all these for a long time, and in an elegant way, but the cost is non-zero.)

Equally, Perl explicitly tried a number of syntactic ways to do something; some stuck as good ideas, some were demonstrated to be... less good. I think it was important to explore and show that a particular approach has serious downsides in practice, but it's not necessary to stick to in once better alternatives are available.

adrian17•2h ago
As for syntax, note that as the author says:

> I do not have access yet to a true C++26 compiler. When C++26 arrive, we will have features such as ‘template for’ which are like ‘for’ loops, but for template metaprogramming. Meanwhile, I use a somewhat obscure ‘expand’ syntax.

In particular, regarding the most cryptic line:

[:expand(nonstatic_data_members_of(^^T, ctx)):] >> [&]<auto member>{

In fact, at least from what I know, `expand()` and this fancy use of `>>` aren't actually part of the standard (the standard proposal uses them as an temporary example in case other features didn't get in). The equivalent (I think) line with the C++26 approved features would be a bit more friendly:

template for (constexpr auto member : nonstatic_data_members_of(^^T, ctx)) {

So while it's still not the prettiest thing in the world and knowing C++, it surely will produce some eldritch metaprogramming abominations, the author's examples made it look slightly uglier than it actually is.

adrian17•1h ago
> If I need compile-time reflection, I'll use a C# program to generate C code.

This isn't reflection though, it's just textual code generation. In a way, it has the same problem's Rust's macros have (and indeed I'd love to have this kind of reflection in Rust). As an example, if you're implementing some kind of automated serialization, given an input struct with several fields, how can you even just find out its size? Or at what offset each field lives? Or if the field can be naively memcpy'd? You can hardcode the values if you do lots of assumptions and restrictions, or you can re-implement the logic the compilers already also do - but IMO it does feel the cleanest to just ask the compiler at compile time, which is exactly what C++ reflection proposal does.

MoonGhost•3h ago
How about thin C++ wrapper? The language with the same features, but more human friendly. It should be easily directly translated to C++. Preferably both ways.
nine_k•3h ago
C++'s semantics are also broken in interesting ways: UB, implicit conversions, arrays, exceptions, exceptions from destructors, etc. Papering over them won't help all that much. It's more efficient to just swallow the bullet and switch to Rust (or maybe Zig).
jandrewrogers•2h ago
Many of these inadvisable semantics are fixable in practice, they are just a default that requires additional effort to minimize or eliminate.

That aside, it isn't that easy to switch languages because C++ is more expressive in a systems context in important ways. Porting existing modern systems C++ to e.g. Rust makes this pretty obvious. (I think porting to Zig would likely be a bit easier but I've never actually tried.)

layer8•2h ago
There are languages like D and Carbon that attempt this. But there are too many existing large C++ code bases to not continue evolving C++ itself as well.
MoonGhost•11m ago
I didn't say replace, but complexity is the biggest barrier for newcomers. A lot of typing comparing to other languages. I use professionally since 90th, the more popular it gets the better. And complexity is the major problem, not memory management like some argue.
sirwhinesalot•2h ago
That's what Herb Sutter's cppfront/cpp2 is meant to do. Same semantics, sane defaults, nicer syntax (IMO).
jasonthorsness•2h ago
Seems like maybe it will be a challenge to use, but like a lot of template stuff the complexity gets buried in the library. The language gets a lot of ridicule but I like the no-compromise push to help programmers eliminate unnecessary runtime work in their programs.
112233•2h ago
Oh noes, the binding of internal compiler state to STL will become even more severe with this. It started slowly. You needed exact magic std::initializer_list definition in your headers to match the code generated by the compiler, or the program would crash. RTTI (that was of little use to programs that tried to avoid standard library) Now there are coroutines and this thing. I feel like it is bye-bye to the completely non-standard compliant practice of using C++ without all the standard library. Where should embedded c++ projects go now that they are not welcome anymore?
jcelerier•2h ago
> Where should embedded c++ projects go now that they are not welcome anymore?

I'm just using all of this on embedded platforms without issues - and can't wait to use reflection there either, it'll be ultra useful for ESP32 and Teensy projects we're working on

dodomodo•2h ago
It's not that hard to just copy the relevant part from the standard library of your platform
adrian17•1h ago
The std::meta stuff are only ever running at compile time, so I don't think this would actually interfere much?
izger•2h ago
C++ became more and more cryptic. Make C++ code creation programmable (templating) by basic c++ syntax at compile time. Make this a part of the standard library.

Mechanical Watch: Exploded View

https://fellerts.no/projects/epoch.html
484•fellerts•7h ago•70 comments

Using Home Assistant, adguard home and an $8 smart outlet to avoid brain rot

https://www.romanklasen.com/blog/beating-brainrot-by-button/
20•remuskaos•1h ago•11 comments

Git Notes: Git's coolest, most unloved­ feature (2022)

https://tylercipriani.com/blog/2022/11/19/git-notes-gits-coolest-most-unloved-feature/
372•Delgan•12h ago•100 comments

How to negotiate your salary package

https://www.complexsystemspodcast.com/episodes/how-to-negotiate-your-salary-package/
152•surprisetalk•3d ago•126 comments

2048 with only 64 bits of state

https://github.com/izabera/bitwise-challenge-2048
78•todsacerdoti•3d ago•17 comments

There's Gold in the Hills

https://longreads.com/2025/06/12/blm-land-enduring-wild-josh-jackson/
7•gmays•3d ago•0 comments

LibRedirect – Redirects popular sites to alternative privacy-friendly frontends

https://libredirect.github.io
352•riffraff•15h ago•86 comments

Show HN: Turn a paper's DOI into its full reference list (BibTeX/RIS, etc.)

https://references.mireklzicar.com
17•mireklzicar•3h ago•5 comments

We’ve had a Denisovan skull since the 1930s—only nobody knew

https://arstechnica.com/science/2025/06/the-controversial-dragon-man-skull-was-a-denisovan/
27•Bluestein•3d ago•2 comments

Why do all browsers' user agents start with "Mozilla/"? (2008)

https://stackoverflow.com/questions/1114254/why-do-all-browsers-user-agents-start-with-mozilla
40•nan60•1h ago•11 comments

I was surprised by how simple an allocator is

https://tgmatos.github.io/allocators-are-for-monkeys-with-typewriters/
58•gilgamesh3•3d ago•22 comments

The cultural decline of literary fiction

https://oyyy.substack.com/p/the-cultural-decline-of-literary
73•libraryofbabel•6h ago•140 comments

TPU Deep Dive

https://henryhmko.github.io/posts/tpu/tpu.html
346•transpute•19h ago•65 comments

Low-Temperature Additive Manufacturing of Glass

https://www.ll.mit.edu/research-and-development/advanced-technology/microsystems-prototyping-foundry/low-temperature
95•LorenDB•4d ago•16 comments

How fast are Linux pipes anyway?

https://mazzo.li/posts/fast-pipes.html
158•keepamovin•14h ago•17 comments

What would happen if you tried to land on a gas giant?

https://www.popsci.com/science/can-we-land-on-jupiter-saturn/
30•Bluestein•2h ago•7 comments

Kilauea volcano errupts, lava more than 1k feet high [video]

https://www.youtube.com/watch?v=oG5zz9Sjw3E
47•asix66•2d ago•23 comments

Show HN: A Tool to Summarize Kenya's Parliament with Rust, Whisper, and LLMs

https://github.com/c12i/bunge-bits
63•collinsmuriuki•4h ago•7 comments

Mbake – A Makefile formatter and linter, that only took 50 years

https://github.com/EbodShojaei/bake
202•rainmans•2d ago•95 comments

Sound As Pure Form: Music Language Inspired by Supercollider, APL, and Forth

https://github.com/lfnoise/sapf
176•mindcrime•19h ago•35 comments

P-Hacking in Startups

https://briefer.cloud/blog/posts/p-hacking/
276•thaisstein•4d ago•124 comments

Largest Wildlife Bridge Spanning 10 Lanes of CA 101 Is Nearly Complete

https://www.thedrive.com/news/worlds-largest-wildlife-bridge-spanning-10-lanes-of-101-freeway-is-nearly-complete
127•PaulHoule•3d ago•69 comments

Show HN: I'm a doctor and built a responsive breathing app for anxiety and sleep

https://apps.apple.com/us/app/lungy-breathing-exercises/id1545223887
75•lukko•12h ago•31 comments

Let's Talk About Writing in Tech

https://www.gmoniava.com/blog/lets-talk-about-writing-in-tech
22•gmoniava•3h ago•10 comments

LaborBerlin: State-of-the-Art 16mm Projector

https://www.filmlabs.org/wiki/en/meetings_projects/spectral/laborberlin16mmprojector/start
205•audionerd•1d ago•34 comments

uBlock Origin Lite Beta for Safari iOS

https://testflight.apple.com/join/JjTcThrV
377•Squarex•1d ago•113 comments

Show HN: Report idling vehicles in NYC (and get a cut of the fines) with AI

https://apps.apple.com/us/app/idle-reporter-for-nyc-dep/id6747315971
105•rafram•4h ago•151 comments

Harry Brearley, the creator of stainless steel (2016)

https://nautil.us/the-father-of-modern-metal-235939/
73•bookofjoe•9h ago•28 comments

Airpass – Easily overcome WiFi time limits

https://airpass.tiagoalves.me/
367•herbertl•4d ago•247 comments

Denmark's Archaeology Experiment Is Paying Off in Gold and Knowledge

https://www.scientificamerican.com/article/denmark-let-amateurs-dig-for-treasure-and-it-paid-off/
198•sohkamyung•4d ago•100 comments