C++ Reflection

Open-source C++ projects categorized as Reflection

Top 23 C++ Reflection Projects

  • entt

    Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more

    Project mention: Focus: A simple and fast text editor written in Jai | news.ycombinator.com | 2023-09-02

    https://pastebin.com/VPypiitk This is a very small experiment i did to learn the metaprogramming features. its an ECS library using the same model as entt (https://github.com/skypjack/entt). In 200 lines or so it does the equivalent of a few thousand lines of template heavy Cpp while compiling instantly and generating good debug code.

    Some walkthrough:

    Line 8 declares a SparseSet type as a fairly typical template. its just a struct with arrays of type T inside. Next lines implement getters/setters for this data structure

    Line 46 Base_Registry things get interesting. This is a struct that holds a bunch of SparseSet of different types, and providers getters/setters for them by type. It uses code generation to do this. The initial #insert at the start of the class injects codegen that creates structure members from the type list the struct gets on its declaration. Note also how type-lists are a native structure in the lang, no need for variadics.

    Line 99 i decide to do variadic style tail templates anyway for fun. I implement a function that takes a typelist and returns the tail, and the struct is created through recursion as one would do in cpp. Getters and setters for the View struct are also implemented through recursion

    Line 143 has the for expansion. This is how you overload the for loop functionality to create custom iterators.

    The rest of the code is just some basic test code that runs the thing.

  • Magic Enum C++

    Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code

    Project mention: What C++ library do you wish existed but hasn’t been created yet? | /r/cpp | 2023-07-08

    I'm not sure this is quite what you're asking for, but this library has been super helpful to me in the past : https://github.com/Neargye/magic_enum

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

  • rttr

    C++ Reflection Library

  • Nameof C++

    Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum

  • cista

    Cista is a simple, high-performance, zero-copy C++ serialization & reflection library.

  • Better Enums

    C++ compile-time enum to string, iteration, in a single header file

    Project mention: How to convert an enum to string in C++ | news.ycombinator.com | 2023-09-30

    I really like better_enums instead of magic_enums. There’s no limit on enum size with it: http://aantron.github.io/better-enums/

    It was heavily used at a former employer of mine, so definitely a solid production-ready solution.

  • pfr

    std::tuple like methods for user defined types without any macro or boilerplate code

    Project mention: Rooting for P1061 "Structured Bindings can introduce a Pack" | /r/cpp | 2023-10-19

    This single feature opens a world of new possiblities. For example, it makes implementing "getting the number of fields" trivial. Furthrmore, and much more importantly, it enables turning a struct into a tuple. Currently, this can only be done by enumerating cases (therefore it's not fully generic), as with Boost PFR. By the way, PFR greatly simplifies our codebases, especially for parts with serialization and/or reflection.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

  • refl-cpp

    Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).

    Project mention: Out of bounds memory access in V8 in Google Chrome prior to 120.0.6099.224 | news.ycombinator.com | 2024-01-25

    You'd be surprised how much friction you'd have for C++ reflection. First, since it's a custom build step, you can do a mix of custom code gen and C++ constexpr/consteval for static reflection. Here's a header-only implementation for adding compile time reflection purely within the language [1]. And v8 already does dynamic code gen as part of its build process (to generate the snapshot to speedup instantiation of the isolate). Dynamic reflection is a must since JS is a dynamic language with reflection support.

    Now of course, I don't know the specific details of reflection needed for the abstractions you reference and clearly V8 is still doing some amount of manual IR generation, so it's possible it would be a substantial investment to actually retrofit those techniques into v8. One would have to do a careful analysis of historical security exploits & specific techniques and their ability to prevent to figure out if it's worth adding those abstractions (especially since there is a potential performance tradeoff as you mention). As I said, I think there's insufficient research in this area to establish a compelling body of best practices (not to take away from the contributions of the GraalJS team to this space).

    [1] https://github.com/veselink1/refl-cpp

  • glaze

    Extremely fast, in memory, JSON and interface library for modern C++

    Project mention: [C++20] to_tuple with compile-time names | /r/cpp | 2023-12-05
  • structopt

    Parse command line arguments by defining a struct (by p-ranav)

  • alpaca

    Serialization library written in C++17 - Pack C++ structs into a compact byte-array without any macros or boilerplate code (by p-ranav)

  • avendish

    declarative polyamorous cross-system intermedia objects

  • Refureku

    Cross-platform C++17 Runtime Reflection Library

  • RareCpp

    Creating a simpler, more intuitive means of C++ reflection

  • meta.hpp

    C++20 Dynamic Reflection Library

  • serdepp

    c++ serialize and deserialize adaptor library like rust serde.rs

  • easy_reflection_cpp

    Reflection brings the best way to serialize/deserialize json and yaml in C++

  • metapp

    C++ runtime reflection library

  • pfr_non_boost

    Boost.PFR without the boost namespaces

  • enum.hpp

    C++17 compile-time enum reflection library

  • enum_name

    Converting (scoped)enum values to string names written in C++>=11.

  • reflect

    A single file header only static reflection library for C++20. (by M-Fatah)

    Project mention: A basic reflection-like system for editing object fields in a C++ game engine | /r/cpp_questions | 2023-05-23

    You can look at it here. If you want to know more about the implementation details, you can read about it here.

  • reflite

    C++ header-only data reflection/introspection

  • SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

NOTE: The open source projects on this list are ordered by number of github stars. The number of mentions indicates repo mentiontions in the last 12 Months or since we started tracking (Dec 2020). The latest post mention was on 2024-01-25.

C++ Reflection related posts

Index

What are some of the best open-source Reflection projects in C++? This list will help you:

Project Stars
1 entt 9,351
2 Magic Enum C++ 4,314
3 rttr 2,943
4 Nameof C++ 1,919
5 cista 1,606
6 Better Enums 1,581
7 pfr 1,250
8 refl-cpp 986
9 glaze 843
10 structopt 450
11 alpaca 409
12 avendish 403
13 Refureku 199
14 RareCpp 113
15 meta.hpp 112
16 serdepp 94
17 easy_reflection_cpp 87
18 metapp 76
19 pfr_non_boost 57
20 enum.hpp 42
21 enum_name 19
22 reflect 14
23 reflite 9
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com