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•13m 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•2h 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•1h 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.
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.

Conscience and the New Cartography of War

https://blogs.timesofisrael.com/conscience-and-the-new-cartography-of-war/
1•bryanrasmussen•34s ago•0 comments

Beach Boys Bassist Carol Kaye Refuses Rock Hall of Fame Induction

https://www.guitarplayer.com/guitarists/carol-kaye-on-rock-hall-of-fame-induction
1•bookofjoe•2m ago•0 comments

Bill Gates: 'Welcome to the next phase of the Alzheimer's fight'

https://www.gatesnotes.com/home/home-page-topic/reader/welcome-to-the-next-phase-of-the-alzheimers-fight
1•MilnerRoute•10m ago•0 comments

Edward Burra's tour of the 20th century

https://www.newstatesman.com/culture/2025/06/the-english-painters-relish-for-subcultures-took-him-across-genres-and-continents
1•prismatic•14m ago•0 comments

USAF B-2 Spirit Bombers Have Beds

https://simpleflying.com/usaf-b-2-spirit-bombers-beds/
2•neom•16m ago•0 comments

Radio Garden

https://radio.garden/?2025
2•LeoPanthera•21m ago•0 comments

Bluetooth Jammer

https://github.com/EmenstaNougat/ESP32-BlueJammer
1•yeknoda•21m ago•0 comments

Wait, Why Is Israel Allowed to Have Nukes?

https://www.currentaffairs.org/news/wait-why-is-israel-allowed-to-have-nukes
38•shinryudbz•22m ago•9 comments

CTO's at Meta, Open AI, Palantir Became Lieutenant Colonels in the Army

https://americancitizen2025.substack.com/p/ctos-at-meta-open-ai-palantir-became
3•brie22•25m ago•0 comments

Claude's Token Efficient Tool Use on Amazon Bedrock

https://community.aws/content/2trguomubYb8f3JNzCeBgNvassc/claude-token-efficient-tool-use-on-amazon-bedrock
1•Topfi•26m ago•0 comments

Tell HN: Sam and Jony Announcement 404s

3•mellosouls•28m ago•2 comments

I built a CLI tool to scaffold Django apps like in NestJS or Larave

https://github.com/nathanrenard3/django-smartcli
1•nathanrenard3•29m ago•1 comments

Call for more thatching courses to save 'uniquely Irish craft'

https://www.rte.ie/news/politics/2025/0618/1519182-thatching-courses/
2•austinallegro•30m ago•0 comments

The Void IDE, Open-Source Alternative to Cursor, Released in Beta

https://www.infoq.com/news/2025/06/void-ide-beta-release/
2•rmason•31m ago•0 comments

Show HN: I made weekend project (Active Directory Security Assessment Tool)

https://adsecurityassessment.com
1•Shazeb•33m ago•0 comments

I Sing the Electric Body – On Syntax (2024)

https://hedgehogreview.com/issues/the-varieties-of-travel-experience/articles/i-sing-the-electric-body
1•rntn•36m ago•0 comments

I wrote my PhD Thesis in Typst

https://fransskarman.com/phd_thesis_in_typst.html
2•todsacerdoti•38m ago•0 comments

I Miss YC – Kanye East

https://twitter.com/jonan_zz/status/1935833004200673719
2•contingencies•39m ago•0 comments

Building my own paper tape punch

https://unimplementedtrap.com/paper-tape-punch
2•todsacerdoti•42m ago•0 comments

Otus Lisp

https://yuriy-chumak.github.io/ol/
1•smartmic•42m ago•0 comments

Owl Lisp

https://haltp.org/posts/owl.html
1•smartmic•43m ago•0 comments

Long-time rivals Bill Gates and Linus Torvalds meet

https://www.tomshardware.com/software/operating-systems/long-time-rivals-bill-gates-and-linus-torvalds-meet-for-the-first-time-have-dinner-no-major-kernel-decisions-were-made-but-maybe-next-dinner
1•LorenDB•43m ago•0 comments

NASA's Hubble Watches Jupiter's Great Red Spot Behave Like a Stress Ball (2024)

https://science.nasa.gov/missions/hubble/nasas-hubble-watches-jupiters-great-red-spot-behave-like-a-stress-ball/
2•Bluestein•45m ago•0 comments

Ask HN: Best books for designing a weekly schedule?

1•yura•46m ago•0 comments

Diagnose Before You Delegate

https://www.subbu.org/articles/2025/diagnose-before-you-delegate/
2•kiyanwang•46m ago•0 comments

Boldly going where no one has gone before? – creating a Discovery backlog

https://markdalgarno.medium.com/boldly-going-where-no-one-has-gone-before-creating-a-discovery-backlog-ae54d4240835
1•kiyanwang•49m ago•0 comments

That Revolutionary May Day in 1976 When California Wines Bested France's Finest

https://www.smithsonianmag.com/smithsonian-institution/that-revolutionary-May-day-1976-when-california-wines-bested-france-finest-180958971/
3•mindracer•51m ago•0 comments

IDF on alert, possible relocation of Iran's enriched uranium from damaged sites

https://www.jpost.com/israel-news/article-858619
2•Bluestein•53m ago•0 comments

Using a Bloom Filter to Anonymize Web Server Logs

https://www.jamieweb.net/blog/using-a-bloom-filter-to-anonymize-web-server-logs/
2•smartmic•56m ago•0 comments

Ask HN: How do you think AI will change education?

1•andrewrn•56m ago•1 comments