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 can be installed in two ways. You can install it using cmake
as an INTERFACE
library, or you can embed it in your project
(e.g. via git submodules
or direct-copy).
You may follow the Installation Guide
for your convenience.
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
.
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.
CppML
is structured as follows:
- each library has an associated header
.hpp
and a directory of the same name in theCppML/
directory. For example, theAlgorithm
library has anAlgorithm.hpp
header located in theinclude/CppML
- every component of each library has a dedicated
.hpp
header inside the libraries associated directory. For example,Sort
, a component of theAlgorithm
library, has a header located atinclude/CppML/Algorithm/Sort.hpp
.
Thus, to use any component, you can either include its specific header (e.g. #include <CppML/Algorithm/Sort.hpp>
), or include its libraries header #include <CppML/Algorithm.hpp>
. Note that you may include all libraries at once using #include <CppML/CppML.hpp>
.
CppML
provides tests
for each of its components, which are automatically built with Github Actions
on each push. Please see the Testing Guide
for instructions on how to build them, and additional details.
CppML
is distributed under the MIT License. Please see the accompanying LICENSE
in the root of the project.