» TypeAsValue

…is a template metaprogramming library intended for compile time computation written in C++.

As its name implies it follows the overall concept of viewing types as values and templates as functions manipulating those values.

This library is a expanded reimplementation of my previous attempt at this problem: ConstList. As detailed in the appropriate blog article the mixed approach between generic lambda expressions, constexpr marked functions and template metaprogramming doesn’t offer sufficient flexibility which led me to approach compile time computation in a slightly different manner via this new library. As one might notice this boils down to using Scheme as a metaphor for C++ template metaprogramming. In fact all test cases and examples are documented by representing their logic in Scheme.

Its MIT licensed source code is available on both Github and cgit.

Furthermore an overview of this library alongside some background information is available in the form of a blog article on using Scheme as a metaphor for template metaprogramming.

Current features

Usage example

// λ (length (filter odd? (list 1 2 3)))
// 2

const std::size_t count = tav::Length<
    tav::Filter<
        tav::Odd,
        tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>
    >
>::value;

More extensive examples are available in the form of implementations of the Sieve of Eratosthenes as well as of a Turing machine.