A concise and readable metaprogramming language for C++
CppML
is a metalanguage for C++
. It was designed to simplify the process of creating intricate classes, by letting the programmer design them through expressions that feel like algorithms in a functional language. It strives to be easy to write and easy to read, while being efficient. It does so by providing compositional pipelines
through which parameter packs
can flow without instantiating new types. Our goal is to give library developers programmatic control over the creation of class hierarchies with metaprograms that shape their structure and behaviour through metafunctional logic. This way constructions of complex designs are easily encoded in concise and readable functional expressions.
An illustrative example is generating a tagged hierarchy of classes
, which is used by some implementations of a tuple
. We want a metafunction MakeBase
, where e.g. MakeBase<T0, T1, T2, T3>
is equivalent to:
Elem<Tag<ml::Int<0>, T0>,
Elem<Tag<ml::Int<1>, T1>,
Elem<Tag<ml::Int<2>, T2>, Elem<Tag<ml::Int<3>, T3>>>>>;
Using CppML
we can express MakeBase
as a simple metaprogram:
template <typename... Ts>
using MakeBase = ml::f<
ml::ZipWith<Tag, ml::Map<ml::Curry<ml::F<Elem>>, ml::F<ml::Compose>>>::f<
ml::Range<>::f<0, sizeof...(Ts)>, ml::ListT<Ts...>>,
EmptyBase>;
To get started please see our User Documentation
, where we provide an Instalation Guide
, an in-depth Tutorial of the CppML language
and a detailed CppML Reference
.
CppML
provides an Installation Guide
which will have you up and running in moments. To quickly install CppML
as a cmake INTERFACE
library, run
git clone https://github.com/ZigaSajovic/CppML; cd CppML
mkdir build && cd build
cmake ..
make install
or simply embed it into your project
(e.g. via git submodules
). Please see the Installation Guide
for additional details.
CppML
provides an in-depth Tutorial of the CppML language
and its libraries.
In this tutorial, we will go over the design of the CppML
language and explore its prominent features in depth. You will learn about compositional pipelines
and the flow of parameter packs
through them. You will learn about the structure of metafunctions
, how to understand their metafunction type
, and how they integrate with pipelines
.
You will learn how to manipulate metafunctions
using concepts like Currying
, Product Maps
and Branch Pipes
, and how to compose them into algorithms that will build your class designs.
Interspersed throughout the tutorial are use-cases, where we will formulate a problem and break down its solution into steps, and than translate them into CppML
. Through them you will learn how to encode construction of (increasingly) complex designs into concise and readable functional expressions.
Please see the Tutorial of the CppML language
.
Complete User documentation
can be found in the docs/
directory.
CppML
comes with a detailed CppML reference
. Each construct provides a specification of its structure, a definition of its metafunction type, and an example of use. The constructs of CppML
are divided in into several smaller libraries, which are described below:
Library | Description |
---|---|
Algorithm |
Algorithms over parameter packs (e.g. Sort , ZipWith , etc.) |
Arithmetic |
Arithmetic operations on type-values (e.g. Greater , Not , etc.) |
Functional |
Manipulation of metafunctions (e.g. Curry , Map , etc.) |
Pack |
Manipulation of parameter packs (e.g. Drop , Get , etc.) |
TypeTraits |
Insights into types (e.g. IsSame , IsClass , etc.) |
Vocabulary |
Vocabulary types of CppML (e.g. ListT , Value , etc.) |
Please see the complete CppML reference
, for additonal details.