C++ Metaprogramming

Open-source C++ projects categorized as Metaprogramming

Top 23 C++ Metaprogramming Projects

Metaprogramming
  1. 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

  2. SaaSHub

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

    SaaSHub logo
  3. Nameof C++

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

  4. hana

    Your standard library for metaprogramming

  5. Experimental Boost.DI

    C++14 Dependency Injection Library

  6. sml

    C++14 State Machine library

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

  8. te

    C++17 Run-time Polymorphism (Type Erasure) library

  9. feelpp

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

  10. lwlog

    Very fast synchronous and asynchronous C++17 logging library

    Project mention: C++ logging library – something I've been working on | news.ycombinator.com | 2025-01-01
  11. 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).

    Project mention: JNI Bind | news.ycombinator.com | 2024-03-12
  12. 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

  13. 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)

  14. protopuf

    Protocol Puffers: A little, highly templated, and protobuf-compatible serialization/deserialization header-only library written in C++20

  15. constexpr-sql

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

  16. Tiger

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

  17. CppML

    A concise and readable metaprogramming language for C++

  18. conjure_enum

    Lightweight header-only C++20 enum and typename reflection

    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.

  19. kumi

    C++20 Compact Tuple Tools

  20. mlib

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

  21. zxorm

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

  22. optimizing-the-memory-layout-of-std-tuple

    Optimizing the memory layout of std::tuple

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

  24. static_string

    Experimental compile-time string manipulation C++17 library

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 discussion

Log in or Post with

C++ Metaprogramming related posts

  • Out of bounds memory access in V8 in Google Chrome prior to 120.0.6099.224

    1 project | news.ycombinator.com | 25 Jan 2024
  • How does Swift implement primitive types in its standard library?

    2 projects | /r/ProgrammingLanguages | 22 Jun 2023
  • What's the most hilarious use of operator overloading you've seen?

    7 projects | /r/cpp | 6 May 2023
  • State machines with C++20 coroutines and Asio/Boost Async

    2 projects | /r/cpp_questions | 8 Apr 2023
  • When Debug Symbols Get Large

    2 projects | news.ycombinator.com | 9 Mar 2023
  • C++ Reflection for Component Serialization and Inspection

    3 projects | /r/gameenginedevs | 4 Mar 2023
  • I implement a fast, macro-based namedtuple works under C++11

    6 projects | /r/cpp | 19 Jan 2023
  • A note from our sponsor - SaaSHub
    www.saashub.com | 19 Jan 2025
    SaaSHub helps you find the best software and product alternatives Learn more →

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

Sponsored
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com

Did you know that C++ is
the 7th most popular programming language
based on number of references?