A Tiny Metaprogramming Library: Boxing – Part 1

A Tiny Metaprogramming Library episode 3:

Last time we introduced the mathematical concept of function as an entity that takes an input, generating an output. In that process, the function does not change any external state.

We also talked about metafunctions, a way to represent functions operating on C++ types using C++ templates.

After the theory, we followed with some conventions about the specific implementation of metafunctions in our tiny metaprogramming library. We decided that:

  • Any type with a type public member type is considered a metafunction, where type represents the result of that metafunction.That means to take the result of a metafunction we should say typename F::type in most of the situations. We introduced a simple tool tml::eval to help a bit.
  • Our metafunctions are templates, but these are constrained to take type parameters only.

In this post we will learn how to use boxing to pass value parameters as type parameters for our metafunctions. This is not something new but a way to understand what std::integral_constant, one of the fundamentals of <type_traits>, is and what can be used for.
Tiny Metaprogramming library episode 3: boxing.

Continue reading