Show HN: Beautiful Type Erasure with C++26 Reflection

RyanJK5 112 points 47 comments July 14, 2026
ryanjk5.github.io · View on Hacker News

Try it on Compiler Explorer: https://godbolt.org/z/91dj5jeGW Check out the source code: https://github.com/RyanJK5/rjk-duck

Discussion Highlights (12 comments)

rob74

The things people describe as "beautiful" never cease to amaze me... ...but, as they say, beauty is in the eye of the beholder!

feverzsj

Reflections, especially static ones, are horrible for debugging.

Leherenn

What's compilation time like when using it? I see there's an issue in the tracker to get more accurate data, and since it's using an under dev feature in compilers, it's not going to be definitive, but any rough numbers?

schaefer

in the first example: ``` 10: rjk::duck<Container> c{std::vector<int>{1, 2, 3}}; 11: c.size(); // 3 12: 13: c = std::string{"hello"}; ``` Does the assignment on line 13 call the destrucor for the vector of ints created on line 10?

briandilley

are we still hand writing code?

gmueckl

An include with a HTTP URL is a scary abomination straight put of hell. Please tell me that this is a compiler explorer specialty (which would still be cursed, but in a cool way) and not a GCC feature (which would be an absolute nightmare).

semiinfinitely

this is the most disgusting programming language ever invented!

usrnm

> If you’ve ever tried using type erasure for something more complicated than std::any or std::function, you’ve either written 100+ lines of easy-to-mess-up code or reached for a boilerplate-heavy library like Boost.TypeErasure or Folly.Poly Or you just used void* and went on with your life

YesBox

I use C++ every day and this feels like an entirely different language and philosophy. I know this is the reality of C++, but I never go searching for it so when it pops up randomly my jaw drops a little.

semiinfinitely

looks like the kind of thing that will compile for 60 seconds only to spew 10k lines of error message to your terminal because you got 1 character wrong

semiinfinitely

People writing incomprehensible slop like this is the reason why some other people felt they had to invent AI coding agents

semiinfinitely

glad to see that in the yaer of our lord 2026 c++ is still slaying, wasting gigawatts of 18yo supple brain energy on useless shit like this

Semantic search powered by Rivestack pgvector
14,015 stories · 131,331 chunks indexed