Twelve posts of theory. Now we build. A complete, type-safe, zero-overhead domain-specific language — using every tool the compile-time language has taught us.
Posts tagged “compile-time-cpp” (13)
The compile-time language has been blind — it can compute with types but can't look inside them. C++26 reflection changes that. The compiler is about to hand you the keys to the AST.
Concepts aren't just prettier SFINAE. They're the type system of the compile-time language — named, composable interfaces that tell the compiler (and the reader) what a type must be.
constexpr started as a way to mark simple constants. Then it grew. And grew. Now it's an entire execution engine inside the compiler, running real algorithms with loops, branches, allocations, and exceptions.
The compile-time language's error messages are notoriously awful. But you can control them — static_assert, concepts, and careful design turn compiler vomit into helpful diagnostics.
String literals live at compile time. With the right tools, you can parse them, validate them, and turn them into optimized code — all before your program runs.
Runtime C++ has std::function and lambdas. Compile-time C++ has metafunctions and template template parameters. Same idea, alien syntax. Welcome to functional programming with angle brackets.
Template specialization isn't just an override mechanism. It's the compile-time language's pattern matching — it takes types apart, examines their bones, and lets you react to their shape.
The compile-time language has arrays, maps, and linked lists. They just look nothing like their runtime counterparts — and they hold types instead of values.
The compile-time language doesn't have for loops. It has something weirder — parameter packs that expand into exactly the code you need, like a copy-paste machine controlled by the compiler.
Every language needs branching. The compile-time language has four different if statements, each invented in a different decade, each a reaction to the last one's shortcomings.
In the compile-time language, types ARE the values. You pass them to functions, store them in data structures, and compute with them. This is the key insight that makes everything else click.
C++ isn't one language. It's two. One runs on your machine. The other runs inside the compiler. This series teaches the second one.