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
-
Nameof C++
Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum
-
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).
-
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.
-
xl
A minimalist, general-purpose programming language based on meta-programming and parse tree rewrites
-
jni-bind
JNI Bind is a set of advanced syntactic sugar for writing efficient correct JNI Code in C++17 (and up).
-
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)
-
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.
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
Project mention: What C++ library do you wish existed but hasn’t been created yet? | /r/cpp | 2023-07-08I'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
Anyway the need is not complicated, I need both entry and exit functions from every state, optionally allowing these functions to be coroutines (that's special sauce but for later), and an explicit state transition table which also have a way to say that a state can be accessed at any point. Also allow states to be state machines, optional FSM hierarchies. If you ignore the coroutine stuff it's pretty standard features these days, except that - Boost.MSM is quite archaic now (it was so novel when it was first released...) although it allows most of the features I talked about, I just think it will complicate my code unneecessarilly; - Boost-Ext.SML (not Boost) is almost perfect except it doesnt have entry/exit functions on states for some reason. Also last time we (as in in livestream) tried it in prototypes it didnt compile on msvc XD - Boost-Ext.SML2 is even better but still doesnt have entry/exit functions although it's in the plans.
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
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
Project mention: What's the most hilarious use of operator overloading you've seen? | /r/cpp | 2023-05-06operator"" can be used in a similar way to expression templates (DSLs), where the type of the resulting expression is dependent on the string contents. For example ctre makes use of this to build efficient regular expression parsers, and kumi uses this in conjunction with operator[] to make tuple indexing quite elegant
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 | 25 Apr 2024
Index
What are some of the best open-source Metaprogramming projects in C++? This list will help you:
Project | Stars | |
---|---|---|
1 | Magic Enum C++ | 4,403 |
2 | Nameof C++ | 1,937 |
3 | hana | 1,633 |
4 | proxy | 1,113 |
5 | Experimental Boost.DI | 1,103 |
6 | sml | 1,072 |
7 | refl-cpp | 986 |
8 | te | 402 |
9 | feelpp | 293 |
10 | xl | 242 |
11 | jni-bind | 221 |
12 | lwlog | 219 |
13 | hsm | 178 |
14 | protopuf | 141 |
15 | constexpr-sql | 132 |
16 | Tiger | 102 |
17 | CppML | 53 |
18 | mlib | 43 |
19 | kumi | 41 |
20 | zxorm | 36 |
21 | optimizing-the-memory-layout-of-std-tuple | 30 |
22 | SpeciaLUT | 26 |
23 | crunchy-bytes | 6 |
Sponsored