C++ Metaprogramming

Open-source C++ projects categorized as Metaprogramming

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

  • 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

  • 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.

    WorkOS logo
  • hana

    Your standard library for metaprogramming

  • proxy

    Proxy: Next Generation Polymorphism in C++ (by microsoft)

  • Experimental Boost.DI

    C++14 Dependency Injection Library

  • sml

    C++14 State Machine library

  • Project mention: Sharing Saturday #496 | /r/roguelikedev | 2023-12-08

    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.

  • 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

  • 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.

    InfluxDB logo
  • te

    C++17 Run-time polymorphism (type erasure) library

  • feelpp

    :gem: Feel++: Finite Element Embedded Language and Library in C++

  • xl

    A minimalist, general-purpose programming language based on meta-programming and parse tree rewrites

  • Project mention: XL: An Extensible Programming Language | news.ycombinator.com | 2024-02-21

    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

  • jni-bind

    JNI Bind is a set of advanced syntactic sugar for writing efficient correct JNI Code in C++17 (and up).

  • Project mention: JNI Bind | news.ycombinator.com | 2024-03-12
  • lwlog

    Very fast synchronous and asynchronous C++17 logging library

  • 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

  • constexpr-sql

    Header only library that parses and plans SQL queries at compile time

  • Tiger

    C++ Matrix -- High performance and accurate (e.g. edge cases) matrix math library with expression template arithmetic operators (by hosseinmoein)

  • CppML

    A concise and readable metaprogramming language for C++

  • mlib

    mlib is a fast, simple c++ meta-programming library that uses c++20. (by robertshepherdcpp)

  • kumi

    C++20 Compact Tuple Tools

  • Project mention: What's the most hilarious use of operator overloading you've seen? | /r/cpp | 2023-05-06

    operator"" 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

  • zxorm

    Zach's ORM - A C++20 ORM for SQLite

  • optimizing-the-memory-layout-of-std-tuple

    Optimizing the memory layout of std::tuple

  • 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.

  • crunchy-bytes

    C++ 17 Schema Serialization Library

  • SaaSHub

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

    SaaSHub logo
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).

C++ Metaprogramming related posts

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
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com