r/cpp
•
u/anilctrn
•
Jun 08 '26
•
2
I built an ECS framework using C++26 static reflection features.
Hey all! Lately, I've been experimenting with C++26 static reflection features using Bloomberg's clang-p2996 compiler fork. I've tried a few different ideas, but this project has definitely been the most exciting for me.
The goal was to build an ECS framework that completely eliminates boilerplate setup. Things like manual component registration, system scheduling, and etc...After a few iterations and millions of demonic consteval errors, I've finally gotten it to a state where I feel like I can share it with public.
Here is RECS (Reflected Entity Component System)
https://github.com/bestofact/recs
Since this relies heavily on P2996, it's highly experimental, but it’s been a really nice exercise in pushing meta programming to its limits. Would be really nice to hear your thoughts on the RECS or any general feedback on the code.
17
u/Natural_Builder_3170 Jun 08 '26 edited Jun 08 '26
I’m reading the readme, and I don’t understand why the component must be an aggregate and trivially copyable, can’t you just require default constructible and copy constructible instead. Even if storage is a contiguous slab you can use placement new or
construct_at?Also for the “system must lack T
query, would it be possible to provide a typerecs::must_lack<T>that has no members, so you can reflect on it usingextract` instead of the rvalue reference and trusting the user not to use itThis looks really nice, reflection really is a drug
6
u/lanwatch Jun 08 '26
Showcases links at the bottom don't work.
Seems very interesting. Will look into this!
2
u/LucyShortForLucas Jun 09 '26
Have you benchmarked its performance against other frameworks like Flecs and ENTT? How does it compare?