Skip to main content
Generative Metaprogramming

GMP Documentation

A modern C++ metaprogramming library for compile-time code generation.

Header-onlyC++20ReflectionMIT
example.cpp
struct Person {
std::string name;
int age;
};
static_assert(gmp::type_name<Person>() == "Person");
static_assert(gmp::member_count<Person>() == 2);
static_assert(gmp::member_name<0, Person>() == "name");
static_assert(gmp::member_name<1, Person>() == "age");

Core Capabilities

Building blocks for expressive compile-time metaprogramming.

Macro Metaprogramming

Preprocessor utilities for boolean logic, arithmetic, tuple manipulation, loops, and overload dispatch.

Reflection Metaprogramming

C++20 features for fixed strings plus type and enum reflection at compile time.

Named Operators

Expressive infix-style named operators for clearer template and metaprogramming code.

Generic Design Patterns

Lightweight infrastructure helpers including singleton and object factory utilities.

Code in Practice

Explore GMP features with real-world examples.

#define PRINT(x) std::cout << x << " ";
GMP_FOR_EACH(PRINT, 1, 2, 3) // Expands to: std::cout << 1 << " "; std::cout << 2 << " "; std::cout << 3 << " ";

#define Bar(arg1, arg2) bar(arg1, arg2);
GMP_REPEAT(Bar, 3, 1, "arg2") // Expands to: bar(1, "arg2"); bar(2, "arg2"); bar(3, "arg2");

GMP_OVERLOAD_INVOKE(OVERLOAD_FUNCTION, X, Y, Z) // expands to: "OVERLOAD_FUNCTION_X_Y_Z"

GMP_MAKE_INDEX_SEQUENCE(5) // expands to: 0, 1, 2, 3, 4
GMP_RANGE(5, 10) // expands to: 5, 6, 7, 8, 9

GMP_GENERATE_NAMESPACES_BEGIN(mylib, parser) // expands to: namespace mylib { namespace parser {
GMP_GENERATE_NAMESPACES_END(mylib, parser) // expands to: } }

Why GMP?

Header-only, zero runtime overhead, capable of generating thousands of lines of code at compile time.