Jacek's Blog

Software Engineering Consultant

Jacek Galowicz's Posts tagged "metaprogramming"

Simple(r) Heterogeneous Mapping of Records in Purescript

February 13, 2023 purescript metaprogramming

Two weeks ago, I blogged about the automatic heterogeneous zipping of records in PureScript. The code was longer than the manual version but at least less error-prone. After learning how to do it this way, I present a neat little library (not mine) that provides all the benefits without the downsides.

Read more


Interpolation of Records of Values in Purescript

January 30, 2023 purescript metaprogramming

This article is about a little interesting detour that I made in one of my personal projects: How to use strong type systems to generically apply a binary mathematical function on all items of a possibly nested record. The code provides interesting insights into other languages with similar type systems.

Read more


Filtering Unique Items from Heterogeneous Lists at Compile Time

March 20, 2022 haskell metaprogramming

This article is about how to filter unique items from heterogeneous lists on the type level in Haskell. This example, without further context, might look a bit esoteric by itself, but I learned a lot writing it and wanted to share the experience.

Read more


Python Style printf for C++ with pprintpp

November 5, 2016 c++ metaprogramming

The C++ STL comes with stream style character output, which is an alternative to the classic printf like format function collection of the C library. For different reasons, some C++ programmers still stick to printf like formatting. This article demonstrates the pprintpp (open source, and available on Github) library, which tries to make printf use comfortable and safe while avoiding any runtime overhead.

Read more


Type List Compile Time Performance

June 25, 2016 c++ metaprogramming

Soon, after writing my first meta programs with C++ templates, i realized, that certain programming patterns lead to sky rocketing compile times. I came up with rules of thumb like “Prefer pattern matching over if_else_t”, and “Prefer nested type lists over variadic type lists”. But i did not know how much faster which pattern is, i just knew about tendencies. Finally, i sat down to write some compile time benchmarks, and this blog posts presents the results.

Read more


Generating Integer Sequences at Compile Time

June 24, 2016 c++ metaprogramming

In some situations, it can be useful ot generate sequences of numbers at compile time. This article shows how to generate integer sequences with C++ templates, and gives an example how to use it.

Read more


Executing Brainfuck at Compile Time with C++ Templates

June 16, 2016 c++ metaprogramming

This article completes a series which aims at explaining how to implement a Brainfuck Interpreter as a template meta-program which runs at compile time.

Read more


Implementing a Turing Tape for Use at Compile Time

May 15, 2016 c++ metaprogramming

Turing Machines consist of a tape with memory cells, a tape reader like cassette drives and a program table. Implementing the tape drive part with an array and a pointer is a trivial thing to do with imperative programming languages. It becomes more interesting when learning purely functional programming, especially in the context of template meta programming in C++. As a preparation for the next article, i will show how to implement a turing tape based on type lists, usable at compile time.

Read more


Transformations between User Input/Output and Type Lists

May 14, 2016 c++ metaprogramming

Type lists are an important way to represent ordered and unordered sets of types at compile time. These types can be real structure- or class types bundling runtime algorithms etc., but they can also convey actual data at compile time. In order to apply certain compile time processing to data, this data needs to be transformed from and to other representations, which can be provided by the programmer and consumed by run time programs. This article shows how to transform back and forth between strings and character type lists.

Read more


Compile Time Type Lists

May 8, 2016 c++ metaprogramming

Homogenuous data in purely functional programs is typically managed in lists. Items can be appended or prepended to lists, different lists can be concatenated. Lists can be filtered, transformed, mapped, reduced, etc. Having all this nice stuff as a template meta library is quite an enabler for complex compile time meta programs.

Read more


Template Metaprogramming Basics

May 5, 2016 c++ metaprogramming

C++ template meta programs are at first really hard to read. This is because the template mechanism accidentally became turing complete, although it was invented to enable for type-agnostic programming of generic algorithms. However, now the world knows that the C++ template part of the language is turing complete, people started writing full programs in it, and it enhances the power and flexibility of libraries quite a lot. This article aims to explain some very basic things one needs to know about the C++ template meta programming language, in order to be able to do things with it, or even understand foreign programs.

Read more


Useful type traits with if_compiles semantics

February 21, 2016 c++ metaprogramming

SFINAE type traits are very mighty, because they can check a lot of properties of types in a non-intrusive way. Unfortunately, they are extremely bloaty to implement. The single interesting expression within an SFINAE type trait is surrounded by lots of boiler plate code, which is ugly to read and repetitive. This article shows a nice one-liner approach to define new SFINAE type traits.

Read more


How Does the Typical SFINAE Type Trait Work?

February 19, 2016 c++ metaprogramming

C++ type traits can be implemented using an interesting technique which uses the SFINAE principle. This article explains what SFINAE means, how it works and how it can be used to implement useful type traits.

Read more


What is a Type Trait?

February 18, 2016 c++ metaprogramming

This article explains, how so called type traits in C++ work. Type traits have been there for quite a long time now. They are a meta programming technique which appears to use types and their sub types like functions at compile time, to control what the compiler actually compiles.

Read more

Newer Older