SaaSHub helps you find the best software and product alternatives Learn more →
Top 23 C++ Metaprogramming Projects
-
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
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
Nameof C++
Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum
-
-
-
-
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-25You'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
-
-
-
Project mention: C++ logging library – something I've been working on | news.ycombinator.com | 2025-01-01
-
jni-bind
JNI Bind is a set of advanced syntactic sugar for writing efficient correct JNI Code in C++20 and up (or C++17 with clang).
-
xl
A minimalist, general-purpose programming language based on meta-programming and parse tree rewrites
From what I can read the author got really unlucky with some kind of radical API changes. Maybe at that time the LLVM team was a bit less serious with deprecations ?
I use LLVM since v9, nowadays I'm stuck on v15 (that's not because of LLVM btw).
Between the two versions there's been a radical change too, i.e "opaque pointers", but the transition was rather smooth as we were provided, for a long time, the two versions of the functions affected by the change. Maybe the LLVM team got more serious since the author experienced the said difficulties ?
Other thing I note is that the author uses the CPP API. I use the C one which exposes only a high-level subset of the CPP one. This encourages a saner use of LLVM, a more concrete separation between the front-end and the mid-end, although sometimes there are limitations.
A simple example of what encourages the C API, especially since opaque ptrs are added, is not to rely on LLVM to retrieve the IR type of an IR value. That should always be done using the AST, eg with an `.ir` field in your nodes.
Another one I remark, after a brief overview of LLVM-CRAP, is that the author had to change the internal data structure used, depending on the LLVM version [0]. Using the C API that would never had happened. The C API essentially allows to create block refs, instructions refs, value refs, type refs, contexts. Then you choose the containers you want to use to hold them. No need to switch to another stdcpp one, even if internally LLVM does so.
[0]: https://github.com/c3d/xl/blob/master/src/llvm-crap.cpp#L265
-
hsm
Finite state machine library based on the boost hana meta programming library. It follows the principles of the boost msm and boost sml libraries, but tries to reduce own complex meta programming code to a minimum. (by erikzenker)
-
protopuf
Protocol Puffers: A little, highly templated, and protobuf-compatible serialization/deserialization header-only library written in C++20
-
-
Tiger
C++ Matrix -- High performance and accurate (e.g. edge cases) matrix math library with expression template arithmetic operators (by hosseinmoein)
-
-
Project mention: 🚀Announcing conjure_enum - a C++20 enum and typename reflection Library | dev.to | 2024-07-31
We're pleased to announce the release of conjure_enum, a lightweight header-only C++20 library designed to streamline working with enums and typenames by providing simple reflection capability.
-
-
-
-
-
SpeciaLUT
Runtime choosing of template specializations using compile-time lookup-tables. Compile all states of a template function, but execute the optimal one at runtime.
-
C++ Metaprogramming discussion
C++ Metaprogramming related posts
-
Out of bounds memory access in V8 in Google Chrome prior to 120.0.6099.224
-
How does Swift implement primitive types in its standard library?
-
What's the most hilarious use of operator overloading you've seen?
-
State machines with C++20 coroutines and Asio/Boost Async
-
When Debug Symbols Get Large
-
C++ Reflection for Component Serialization and Inspection
-
I implement a fast, macro-based namedtuple works under C++11
-
A note from our sponsor - SaaSHub
www.saashub.com | 19 Jan 2025
Index
What are some of the best open-source Metaprogramming projects in C++? This list will help you:
# | Project | Stars |
---|---|---|
1 | Magic Enum C++ | 5,116 |
2 | Nameof C++ | 2,120 |
3 | hana | 1,715 |
4 | Experimental Boost.DI | 1,178 |
5 | sml | 1,177 |
6 | refl-cpp | 1,078 |
7 | te | 463 |
8 | feelpp | 310 |
9 | lwlog | 278 |
10 | jni-bind | 271 |
11 | xl | 270 |
12 | hsm | 191 |
13 | protopuf | 155 |
14 | constexpr-sql | 139 |
15 | Tiger | 116 |
16 | CppML | 58 |
17 | conjure_enum | 53 |
18 | kumi | 47 |
19 | mlib | 45 |
20 | zxorm | 40 |
21 | optimizing-the-memory-layout-of-std-tuple | 33 |
22 | SpeciaLUT | 26 |
23 | static_string | 7 |