SaaSHub helps you find the best software and product alternatives Learn more →
Top 20 C++ compile-time Projects
-
The problem can occur in general if there is a greedy match within the regex: https://github.com/hanickadot/compile-time-regular-expressio...
Although it looks like that this got fixed for simple patterns.
-
InfluxDB
InfluxDB – Built for High-Performance Time Series Workloads. InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
-
lazy_importer
library for importing functions from dlls in a hidden, reverse engineer unfriendly way
-
-
UNITS
a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
Project mention: Python type hints may not be not for me in practice | news.ycombinator.com | 2024-11-27I suspect C++ still comes the closest to what you’re asking for today, at least among mainstream programming languages.
Matrix dimensions are certainly doable, for example, because templates representing mathematical types like matrices and vectors can be parametrised by integers defining their dimension(s) as well as the type of an individual element.
You can also use template wizardry to write libraries like mp-units¹ or units² that provide explicit representations for numerical values with units. You can even get fancy with user-defined literals so you can write things like 0.5_m and have a suitably-typed value created (though that particular trick does get less useful once you need arbitrary compound units like kg·m·s⁻²).
Both of those are fairly well-defined problems and the solutions available do provide a good degree of static checking at compile time.
IMHO, the range question is the trickiest one of your three examples, because in real mathematical code there are so many different things you might want to constrain. You could define a parametrised type representing open or closed ranges of integers between X and Y easily enough, but how far down the rabbit hole do you go? Fractional values with attached precision/error metadata? The 572 specific varieties of matrix that get defined in a linear algebra textbook, and which variety you get back when you compute a product of any two of them?
¹ https://mpusz.github.io/mp-units/
² http://nholthaus.github.io/units/
-
ctpg
Compile Time Parser Generator is a C++ single header library which takes a language description as a C++ code and turns it into a LR1 table parser with a deterministic finite automaton lexical analyzer, all in compile time.
-
au
A C++14-compatible physical units library with no dependencies and a single-file delivery option. Emphasis on safety, accessibility, performance, and developer experience. (by aurora-opensource)
-
The question is - Can we do better? And if so, what are the trade-offs? All in all, wouldn't be great to be able to write the same code for run-time and compile-time and/or debug compile-time code at run-time?
Reflection for C++ - https://wg21.link/P2996 - introduced a new meta-programming model which is value/consteval based and can greatly improve the experience. Together with reflection is a very powerful combination but it also has its own set of trade-offs such as slower compilation-times.
This post is about `mp` - https://github.com/boost-ext/mp - meta-programming library which supports - similar to P2996 - meta-programming model for easier transition as it supports C++20 (msvc, gcc, clang), has a bit faster compilation times than P2996, but mostly, it makes meta-programming a 'normal' C++. In the mp world no difference between run-time and compile-time, whole standard library can be leveraged and it has reflection integration with C++20 using https://github.com/boost-ext/reflect. Of course it has it own set of trade-offs but, IMHO, it has a lot of potential and it's super fan.
> Example (API)
// mp::meta
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
-
-
-
-
static-functional
Header-only C++ library providing compile-time functional operators that work with raw function pointers
-
-
-
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
C++ compile-time discussion
C++ compile-time related posts
-
C++20 – Back to the Future Meta-Programming
-
Force compiler to construct strings dynamically on the stack (win64)
-
Code criticism on decrypt function
-
How to filter tuple at compile time, by values of its elements (instead of types) ?
-
Is there a crossplatform way to write Simd?
-
Compile Time Parser Generator - 1.3.6
-
Compile Time Parser Generator
-
A note from our sponsor - SaaSHub
www.saashub.com | 21 May 2025
Index
What are some of the best open-source compile-time projects in C++? This list will help you:
# | Project | Stars |
---|---|---|
1 | compile-time-regular-expressions | 3,551 |
2 | lazy_importer | 1,749 |
3 | xorstr | 1,306 |
4 | UNITS | 998 |
5 | ctpg | 472 |
6 | au | 362 |
7 | mp | 281 |
8 | pure_simd | 230 |
9 | eternal | 210 |
10 | sml | 209 |
11 | CTAsm | 78 |
12 | static-functional | 49 |
13 | mlib | 46 |
14 | uninttp | 27 |
15 | SpeciaLUT | 26 |
16 | enum_name | 21 |
17 | compile_time_regexp.h | 17 |
18 | static_string | 8 |
19 | lambda-tuple | 6 |
20 | typo | 2 |