FUNCTIONAL METAPROGRAMMING WITH LAMBDA META-EXPRESSIONS IN MODERN C++
This paper continues the authors’ earlier work on lambda meta-expressions. These are C++20 lambdas whose call operator is a template over types, so that they act as metafunctions. Template metaprogramming in C++ has a strong relationship with functional programming, but for a long time this relationship was not reflected in the language itself. Lambda meta-expressions bring it into the language: they are written directly in C++, without auxiliary class templates, libraries or translators. We show how lambda meta-expressions filter type lists and form linear type pipelines through a composition combinator. Each step of a pipeline should return the tag std::type_identity<X> rather than a value of type X, and we explain why. We then introduce composition of meta-expressions with one another. With static_assert, we verify that the identity and associativity laws of a category hold for this composition. All examples compile with GCC, Clang and MSVC. Finally, we relate the approach to earlier work by Porkoláb, Sinkovics and Šefl. Its novelty lies not in first-class metafunctions as such, but in obtaining them from a language construct.
Authors
- Volodymyr Boublik (ORCID: https://orcid.org/0000-0002-9009-5730)
- Ruslan Zymovets
Institutions
- National University (PH)
- National University (US)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-11-22
- DOI
- https://doi.org/10.5281/zenodo.24444506
- Primary Topic
- Logic, programming, and type systems
- Type
- preprint